Helo guys,
I am having this "Subscript out of range ( Run time Error: 09)" error whenever trying to execute the below codes in my excel VBA editor:
=================================
Example: 1
Sub ExtractText()
Worksheets("SplitCell").Activate
Dim splitText As Variant
splitText = Split(Worksheets("SplitCell").Cells(2, 1).Value, """")
Worksheets("SplitCell").Cells(5, 2).Value = Trim(splitText(1))
End Sub
===========================================
Example: 2
Sub names2()
Dim namesRng As Range, cell As Range
Dim arr As Variant
Dim fName As String, mName As String, lName As String
Set namesRng = ActiveSheet.Range("A2:A10") '<== here set the actual range of "Data", header excluded
For Each cell In namesRng.SpecialCells(xlCellTypeConstants, xlTextValues)
arr = Split(cell.Value, ",")
lName = Trim(arr(0))
If UBound(arr) = 2 Then lName = lName & " " & Trim(arr(2))
arr = Split(Trim(arr(1))) (Showing the same error here aswell)
fName = Trim(arr(0))
mName = ""
If UBound(arr) = 1 Then mName = Trim(arr(1))
cell.Offset(, 1).Resize(, 3) = Array(fName, mName, lName)
Next cell
End Sub
==========================================
Can anybody help me to fix this out?
During debug it shows that problem is happening here -> Worksheets("SplitCell").Cells(5, 2).Value = Trim(splitText(1)) ( Example 1) And arr = Split(Trim(arr(1))) ( Examle 2)
I tried to solve this error in every possible way that I found in the web. but unfortunately could not solve.
your quick response and help will be highly appreciated. Thanks in Advance!!
Regards
Sharif 007
I am having this "Subscript out of range ( Run time Error: 09)" error whenever trying to execute the below codes in my excel VBA editor:
=================================
Example: 1
Sub ExtractText()
Worksheets("SplitCell").Activate
Dim splitText As Variant
splitText = Split(Worksheets("SplitCell").Cells(2, 1).Value, """")
Worksheets("SplitCell").Cells(5, 2).Value = Trim(splitText(1))
End Sub
===========================================
Example: 2
Sub names2()
Dim namesRng As Range, cell As Range
Dim arr As Variant
Dim fName As String, mName As String, lName As String
Set namesRng = ActiveSheet.Range("A2:A10") '<== here set the actual range of "Data", header excluded
For Each cell In namesRng.SpecialCells(xlCellTypeConstants, xlTextValues)
arr = Split(cell.Value, ",")
lName = Trim(arr(0))
If UBound(arr) = 2 Then lName = lName & " " & Trim(arr(2))
arr = Split(Trim(arr(1))) (Showing the same error here aswell)
fName = Trim(arr(0))
mName = ""
If UBound(arr) = 1 Then mName = Trim(arr(1))
cell.Offset(, 1).Resize(, 3) = Array(fName, mName, lName)
Next cell
End Sub
==========================================
Can anybody help me to fix this out?
During debug it shows that problem is happening here -> Worksheets("SplitCell").Cells(5, 2).Value = Trim(splitText(1)) ( Example 1) And arr = Split(Trim(arr(1))) ( Examle 2)
I tried to solve this error in every possible way that I found in the web. but unfortunately could not solve.
your quick response and help will be highly appreciated. Thanks in Advance!!
Regards
Sharif 007