I am attempting to "convert" stings containing SSNs from one format to another.
From:
123-45-6789
To:
123456789
So, along those lines, as part of a larger VBA procedure, I have a loop that is finding those cells that have a SSN in the first format, and I am attempting (using an array and the SPLIT function)to take out the dashes. But for whatever reason, I keep getting an error message when I first start with the array. I've also tried a couple different methods for looking at the data. I'll detail the code and error message below:
I tried Split(Cells(lngRow, 3).Formula, "-") as well as the current method of looking at the cell as a Range.
Here is the actual error message I keep receiving:
At first I was trying For intArray = 0 to UBound(...) but neither change there seems to make a difference.
The error code comes up on this line of code:
For intArray = LBound(strFormulaArray) To UBound(strFormulaArray)
If I hover over the variables,LBound(..) and UBound(...), VBA says "variable = <subscript out of range>"
Any thoughts/suggestions?
Oh, and I did double check. The string where this is occuring is the first SSN text with the format 123-45-6789
Thanks in advance for any advice/suggestions.
--
"If to err is human, then I must be some kind of human!" -Me
From:
123-45-6789
To:
123456789
So, along those lines, as part of a larger VBA procedure, I have a loop that is finding those cells that have a SSN in the first format, and I am attempting (using an array and the SPLIT function)to take out the dashes. But for whatever reason, I keep getting an error message when I first start with the array. I've also tried a couple different methods for looking at the data. I'll detail the code and error message below:
Code:
Dim lngRow As Long
Dim strFormulaArray() As String
Dim intArray As Integer 'Count of array
Dim strNewFormula As String
For lngRow = tr To br
If InStr(Cells(lngRow, 8), "SSN") Then
If InStr(Cells(lngRow, 3), "-") Then
strForumlaArray = Split(Range("C" & lngRow).Formula, "-")
For intArray = LBound(strFormulaArray) To UBound(strFormulaArray)
If intArray = 0 Then
strNewFormula = strFormulaArray(0)
Else
strNewFormula = strNewFormula & strFormulaArray(intArray)
End If
Next intArray
Cells(lngRow, 3).Formula = strNewFormula
End If
End If
Next lngRow
I tried Split(Cells(lngRow, 3).Formula, "-") as well as the current method of looking at the cell as a Range.
Here is the actual error message I keep receiving:
Run-time error '9':
Subscript out of range
At first I was trying For intArray = 0 to UBound(...) but neither change there seems to make a difference.
The error code comes up on this line of code:
For intArray = LBound(strFormulaArray) To UBound(strFormulaArray)
If I hover over the variables,LBound(..) and UBound(...), VBA says "variable = <subscript out of range>"
Any thoughts/suggestions?
Oh, and I did double check. The string where this is occuring is the first SSN text with the format 123-45-6789
Thanks in advance for any advice/suggestions.
--
"If to err is human, then I must be some kind of human!" -Me