Option Explicit
Sub DeathToApostrophe()
Dim s As Range, temp As String
If MsgBox("Are you sure you want to remove all leading apostrophes from the entire sheet?", _
vbOKCancel + vbQuestion, "Remove Apostrophes") = vbCancel Then Exit Sub
Application.ScreenUpdating = False
For Each s In ActiveSheet.UsedRange
If s.HasFormula = False Then
'Gets text and rewrites to same cell without the apostrophe.
s.Value = s.Text
End If
Next s
Application.ScreenUpdating = True
End Sub
Sub AddApostrophes()
Dim cel As Range
Dim strw As String
strw = "You cannot undo this task."
strw = strw & " You may want to save your work to a new file."
strw = strw & " Press OK to proceed, Cancel to quit."
If vbCancel = MsgBox(strw, vbOKCancel + vbCritical, "Task Cannot Be Undone") Then Exit Sub
For Each cel In ActiveSheet.UsedRange
cel.Value = "'" & cel.Value
Next cel
End Sub
How to use
Sub DeathToApostrophe()
Dim s As Range, temp As String
If MsgBox("Are you sure you want to remove all leading apostrophes from the entire sheet?", _
vbOKCancel + vbQuestion, "Remove Apostrophes") = vbCancel Then Exit Sub
Application.ScreenUpdating = False
For Each s In ActiveSheet.UsedRange
If s.HasFormula = False Then
'Gets text and rewrites to same cell without the apostrophe.
s.Value = s.Text
End If
Next s
Application.ScreenUpdating = True
End Sub
Sub AddApostrophes()
Dim cel As Range
Dim strw As String
strw = "You cannot undo this task."
strw = strw & " You may want to save your work to a new file."
strw = strw & " Press OK to proceed, Cancel to quit."
If vbCancel = MsgBox(strw, vbOKCancel + vbCritical, "Task Cannot Be Undone") Then Exit Sub
For Each cel In ActiveSheet.UsedRange
cel.Value = "'" & cel.Value
Next cel
End Sub
How to use
- Copy above code.
- In Excel press Alt + F11 to enter the VBE.
- Right-click desired file on left.
- Choose Insert -Module.
- Paste code into the right pane.
- Press Alt + Q to close the VBE.
- Save workbook before any other changes.
- Ensure Active sheet is the desired sheet.
- Press Alt + F8.
- Choose 'DeathToApostrophe'.
- Press 'Run'.
- Confirm with 'Ok' to run.
No comments:
Post a Comment