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?
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