"Run-time Error '9': Subscript out of range" - Solution?

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

 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
What are the values of Count and Pos when you get the error, and what's the value of Entries?
 
Upvote 0
Joe,
Thanks for the response. VBA indicates that the error is occurring at line 43, column 1. I'm not certain that this is what you're asking for however. Again, I'm a novice (at best) . Let me know if I need to dig deeper to provide you with this information. Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,826
Messages
6,181,192
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top