Tim Hanson
Member
I am trying to apply the UDF to the used range to remove any leading "-" but I am not getting how to write the Sub so as to input the "-"
Thanks for any help
Thanks for any help
Code:
Sub RemoveFirstCharIF()
Dim myArray As Variant
Dim ws As Worksheet
Dim LastRow As Long
Dim LastCol As Long
Dim x As Long
Dim y As Long
Set ws = ThisWorkbook.Sheets("AAPIP_Data_Prepped")
With ws
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
LastRow = .Cells(.Rows.Count, LastCol).End(xlUp).Row
End With
With ws
myArray = .Range(.Cells(1, 1), .Cells(LastRow, LastCol))
End With
For x = LBound(myArray) To UBound(myArray)
For y = LBound(myArray, 2) To UBound(myArray, 2)
myArray(x, y) = RFC(myArray(x, y))
Next y
Next x
ws.Range(Cells(1, 1), Cells(LastRow, LastCol)) = myArray
End Sub
'\\ Remove 1st Char If... and change to something else...
'RFC
Public Function RFC(ByVal RemFstChar As String) As String
If Left(RemFstChar, 1) = "1" Then
RemFstChar = Replace(RemFstChar, "1", "")
End If
RFC = RemFstChar
End Function