j611obrien
New Member
- Joined
- May 24, 2017
- Messages
- 2
I have a list of data that includes contact info for realtors in my area. My desire for the macro was to take this list of data and move the data into a associated column for that data so that I could have a table of data. For example, move the persons name to the name column, phone number to phone number column, etc. With the help of another user, we created a macro that accomplished that flawlessly for a while. Now I'm getting the below error. It should be stated that I am a novice in VBA. Can someone assist? Any help is greatly appreciated. Thanks!
Error:
"Run-time Error '9': Subscript out of range".
When I step into the VBA the MyArray(Count, Pos) = T is highlighted. So I assume it's getting hung up there. Can you assist? Thanks.
Sub SWMRIC()
'
' SWMRIC Macro
'
With ActiveSheet.UsedRange
SR = .Row
SC = .Column
LR = .Rows(UBound(.Value)).Row
LC = .Columns(UBound(.Value, 2)).Column
End With
'Write Titles
Titles = Array("Name", "Company", "Tel.1", "Tel.2", "Email", "See.1", "See.2", "Member Of:")
Range("B2:I2").Value = Titles
'How Many Entries do we have?
Entries = Application.WorksheetFunction.CountIf(Range("A:A"), "*@*")
ReDim MyArray(Entries - 1, 7)
'Read Data into VBA
InputA = Range(Cells(SR, SC), Cells(LR, SC)).Value
StartPos = 1
'We need to do this for every Entry.
For Count = 0 To Entries - 1
Pos = 0
TFlag = 0
EndPos = Range(Cells(StartPos + 1, 1), Cells(LR, 1)).Find("Member Of ", LookIn:=xlValues, Lookat:=xlPart).Row - 1
'We need to do this for every line of the entry.
For Count2 = StartPos To EndPos
T = InputA(Count2, 1)
If InStr(T, "@") > 0 Then MyArray(Count, 4) = T: GoTo Skip
If Left(T, 1) = "(" Then MyArray(Count, 2 + TFlag) = T: TFlag = 1: GoTo Skip
If Left(T, 9) = "Member of" Then MyArray(Count, 7) = T: GoTo Skip
MyArray(Count, Pos) = T: Pos = Pos + 1: If Pos = 2 Then Pos = 5
Skip:
Next
StartPos = EndPos + 1
Next
'Save The Sorted Data to Spreadsheet
Range("B3:I" & Entries + 2).Value = MyArray
End Sub
Error:
"Run-time Error '9': Subscript out of range".
When I step into the VBA the MyArray(Count, Pos) = T is highlighted. So I assume it's getting hung up there. Can you assist? Thanks.
Sub SWMRIC()
'
' SWMRIC Macro
'
With ActiveSheet.UsedRange
SR = .Row
SC = .Column
LR = .Rows(UBound(.Value)).Row
LC = .Columns(UBound(.Value, 2)).Column
End With
'Write Titles
Titles = Array("Name", "Company", "Tel.1", "Tel.2", "Email", "See.1", "See.2", "Member Of:")
Range("B2:I2").Value = Titles
'How Many Entries do we have?
Entries = Application.WorksheetFunction.CountIf(Range("A:A"), "*@*")
ReDim MyArray(Entries - 1, 7)
'Read Data into VBA
InputA = Range(Cells(SR, SC), Cells(LR, SC)).Value
StartPos = 1
'We need to do this for every Entry.
For Count = 0 To Entries - 1
Pos = 0
TFlag = 0
EndPos = Range(Cells(StartPos + 1, 1), Cells(LR, 1)).Find("Member Of ", LookIn:=xlValues, Lookat:=xlPart).Row - 1
'We need to do this for every line of the entry.
For Count2 = StartPos To EndPos
T = InputA(Count2, 1)
If InStr(T, "@") > 0 Then MyArray(Count, 4) = T: GoTo Skip
If Left(T, 1) = "(" Then MyArray(Count, 2 + TFlag) = T: TFlag = 1: GoTo Skip
If Left(T, 9) = "Member of" Then MyArray(Count, 7) = T: GoTo Skip
MyArray(Count, Pos) = T: Pos = Pos + 1: If Pos = 2 Then Pos = 5
Skip:
Next
StartPos = EndPos + 1
Next
'Save The Sorted Data to Spreadsheet
Range("B3:I" & Entries + 2).Value = MyArray
End Sub