Receiving Error 1004 With InputBoxes

ashperson95

New Member
Joined
May 16, 2014
Messages
36
Hi again,

I am using Input Boxes to fill in information in a table. I'm getting a runtime error 1004 (Application-defined or Object defined) when I tried extending the range one column over and filling that in with an Input Box. I'm not sure what the problem is. Could someone help me?

Code:
Sub EnterLocationInfo()Dim locations As Integer
Dim lightrows As Long
Dim InfoInput As Range
Dim locationNum As Integer
Dim fixtures As Integer
lightrows = Range("Table2").Rows.Count
locations = Application.InputBox("How many locations do you have?", "Location Input", , , , , , Type:=1)


If locations > lightrows Then
Do Until locations = lightrows
ListObjects("Table2").ListRows.Add
AlwaysInsert = True
lightrows = Range("Table2").Rows.Count
Loop
End If


If locations < lightrows Then
Do Until locations = lightrows
ActiveSheet.ListObjects("Table2").ListRows(lightrows).Delete
lightrows = Range("Table2").Rows.Count
Loop
End If

'This block of code is where I'm receiving the error
locationNum = 1
For Each InfoInput In Range("Table2[Location]", "Table2[# of Fixtures]")
InfoInput.Value = InputBox("Name of location " & locationNum, "Name of Location")
fixtures = InputBox("How many fixtures does location " & locationNum & " have?")
InfoInput.Offset(, 1).Value = fixtures
locationNum = locationNum + 1
Next InfoInput
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
The syntax on your range line is wrong. Try this:
Code:
For each InfoInput in Range(Range("Table2[Location]"), Range("Table2[# of Fixtures]"))
 
Upvote 0
On which line?

I know it's in one or all of these lines:

Code:
For Each InfoInput In Range(Range("Table2[Location]"), Range("Table2[# of Fixtures]"))
fixtures = InputBox("How many fixtures does location " & locationNum & " have?")
InfoInput.Offset(, 1).Value = fixtures

Because before I inserted the fixtures input box and the offset line, and before I changed the range from one column to two, it was working fine.
 
Upvote 0
I know it's in one or all of these lines:

Code:
For Each InfoInput In Range(Range("Table2[Location]"), Range("Table2[# of Fixtures]"))
fixtures = InputBox("How many fixtures does location " & locationNum & " have?")
InfoInput.Offset(, 1).Value = fixtures

Because before I inserted the fixtures input box and the offset line, and before I changed the range from one column to two, it was working fine.
Did you click Debug to see which line is highlighted?
 
Upvote 0
It's in this line:
Code:
For Each InfoInput In Range(Range("Table2[Location]"), Range("Table2[# of Fixtures]"))

I just tried taking out the second range (so now it's only location on that line), and just using the offset that way, and it works! I'm not sure why but it does. So now it's just this:

Code:
locationNum = 1For Each InfoInput In Range("Table2[Location]")
InfoInput.Value = InputBox("Name of location " & locationNum, "Name of Location")
fixtures = InputBox("How many fixtures does location " & locationNum & " have?")
InfoInput.Offset(, 1).Value = fixtures
locationNum = locationNum + 1
Next InfoInput
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,269
Messages
6,129,813
Members
449,538
Latest member
cookie2956

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