I have a source file that contains some data in column W. This data is formatted as General and structured like 12345-ABC_6789. Each of the 3 segments is dynamic in length and content. I'm trying to replace the - and _ with a comma, so that I can do text to columns, but Excel is saying it can't find a - or _; even if I try it manually. They are clearly present and the sheet is not protected, so I'm at a loss.
VBA Code:
Sub ImportRetData()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim m As Workbook, s As Workbook
Dim mD As Worksheet, sD As Worksheet
Dim fP As String, fN As String, fE As String
Dim MaxDt As Date
Dim mDLR As Long, mNLR As Long, sDLR As Long
Set m = ThisWorkbook
Set mD = m.Sheets("New Data")
mDLR = mD.Range("A" & Rows.Count).End(xlUp).Row
fP = "C:\Users\Import Files\"
fN = "RetResults"
fN = Dir(fP & fN & "*.xlsx")
Set s = Workbooks.Open(fP & fN)
Set sD = s.Sheets("Data")
sDLR = sD.Range("A" & Rows.Count).End(xlUp).Row
sD.Activate
'Removes filters from the working data if any exist.
If sD.AutoFilterMode Then sD.AutoFilterMode = False
'Unhides any columns and rows that may be hidden on the working data.
With sD.UsedRange
.Columns.EntireColumn.Hidden = False
.Rows.EntireRow.Hidden = False
End With
sD.Range("W2:W" & sDLR).Replace What:="_", Replacement:=",", MatchCase:=False
sD.Range("W2:W" & sDLR).Replace What:="-", Replacement:=",", MatchCase:=False
With sD.Range("W2:W" & sDLR)
.TextToColumns Destination:=sD.Range("W2"), DataType:=xlDelimited, Comma:=True, FieldInfo:=Array(Array(1, 9), Array(2, 2), Array(3, 9)), TrailingMinusNumbers:=True
End With
s.Close SaveChanges:=False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub