VBA Error 9. HELP!

kpurev

New Member
Joined
Nov 14, 2013
Messages
1
Hey guys, when I try to run macro, it is giving me error 9. Please help!!! Here is my coding, and I cannot figure out what is wrong with it.

Sub HR_Amazon()
Dim sVariable As String
Dim vEntry As Variant
Dim iCounter As Integer
Dim iCounter2 As Integer
Dim iCounter3 As Integer
Dim aiRecordLocator() As Integer


For iCounter = 1 To 2500
If Left(Sheets("Sheet1").Range("A1").Offset(iCounter - 1, 0), 6) = "Record" Then
iRecordCounter = iRecordCounter + 1
ReDim Preserve aiRecordLocator(1 To iRecordCounter)
aiRecordLocator(iRecordCounter) = iCounter
End If

Next iCounter

For iCounter = 1 To 400
For iCounter2 = aiRecordLocator(iCounter) To (aiRecordLocator(iCounter + 1) - 2)
For iCounter3 = 1 To (Sheets("Sheet1").Range("A1").Offset(iCounter2, 0).End(xlToRight).Column - 1) Step 2

sVariable = Sheets("Sheet1").Range("A1").Offset(iCounter2, iCounter3)
vEntry = Sheets("Sheet1").Range("A1").Offset(iCounter2, iCounter3 + 1)

If sVariable = "Competing Local Firms" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 0) = vEntry
ElseIf sVariable = "Avg. Longevity" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 1) = vEntry
ElseIf sVariable = "Avg. Salary" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 2) = vEntry
ElseIf sVariable = "Avg. Education (Yrs.)" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 3) = vEntry
ElseIf sVariable = "Avg. Height" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 4) = vEntry
ElseIf sVariable = "Avg. Household Size" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 5) = vEntry
ElseIf sVariable = "Region" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 6) = vEntry
ElseIf sVariable = "Coast" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 7) = vEntry
ElseIf sVariable = "Budget Boost" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 8) = vEntry
ElseIf sVariable = "Proportion Male" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 9) = vEntry
ElseIf sVariable = "Local Unemployment" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 10) = vEntry
ElseIf sVariable = "Avg. Age" Then
Sheets("Sheet2").Range("A1").Offset(iCounter, 11) = vEntry
End If

Next iCounter3
Next iCounter2
Next iCounter

End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
try changing For iCounter2 = aiRecordLocator(iCounter) To (aiRecordLocator(iCounter + 1) - 2)
to For iCounter2 = LBound(aiRecordLocator) To UBound(aiRecordLocator)
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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