Good morning all,
I have a quick question, not actually a problem. I have a very simple piece of code that will replace all the spaces in a selection with underscores. I mainly use it to clean up header rows. My question is, based on the code below, is there a way that this can be done better? And is the error handling sufficient for what I am trying to accomplish?
Very much appreciated,
I have a quick question, not actually a problem. I have a very simple piece of code that will replace all the spaces in a selection with underscores. I mainly use it to clean up header rows. My question is, based on the code below, is there a way that this can be done better? And is the error handling sufficient for what I am trying to accomplish?
Very much appreciated,
Code:
Sub Convert_Space_To_Underscore()
'Error handling
On Error GoTo Error_Handler
Dim sValue As String
For Each CELL In Selection
sValue = Trim(CELL.Value)
sValue = Replace(sValue, " ", "_")
CELL.Value = sValue
Next CELL
Error_Handler:
MsgBox "Error No. " & Err.Number & vbCrLf & "Description: " & Err.Description, vbExclamation, "Database Error"
Err.Clear
Exit Sub
End Sub