Macro "Range' of object" failed

Enragedpanda

New Member
Joined
Jun 8, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Looking for someone to take a look at my code. It runs up to Range("A4") but not past that. When i run each row by itself it'll run the user form i created. Thank you to anyone that helps/provides advice,


VBA Code:
Private Sub CheckBox4_Click()

End Sub

Private Sub CheckBox6_Click()

End Sub

Private Sub CommandButton1_Click()

Sheet2.Activate


Range("A4").End(xlDown).Offset(1, 0).Value = TextBox1.Value

Range(“B4”).End(xlDown).Offset(1, 0).Value = TextBox2.Value

Range(“C4”).End(xlDown).Offset(1, 0).Value = ComboBox1.Value

Range(“D4”).End(xlDown).Offset(1, 0).Value = TextBox3.Value

Range(“E4”).End(xlDown).Offset(1, 0).Value = TextBox4.Value

Range(“F4”).End(xlDown).Offset(1, 0).Value = TextBox5.Value

Range(“G4”).End(xlDown).Offset(1, 0).Value = TextBox6.Value

Range(“H4”).End(xlDown).Offset(1, 0).Value = TextBox7.Value

Range(“I4”).End(xlDown).Offset(1, 0).Value = TextBox8.Value

Range(“J4”).End(xlDown).Offset(1, 0).Value = TextBox9.Value

If CheckBox1.Value = True Then

Range(“K4”).End(xlDown).Offset(1, 0).Value = “Yes”

Else

Range(“K4”).End(xlDown).Offset(1, 0).Value = “No”

End If

If CheckBox2.Value = True Then

Range(“L4”).End(xlDown).Offset(1, 0).Value = “Yes”

Else

Range(“L4”).End(xlDown).Offset(1, 0).Value = “No”

End If

If CheckBox3.Value = True Then

Range(“M4”).End(xlDown).Offset(1, 0).Value = “Yes”

Else

Range(“M4”).End(xlDown).Offset(1, 0).Value = “No”

End If

Range(“N4”).End(xlDown).Offset(1, 0).Value = TextBox11.Value

Range(“O4”).End(xlDown).Offset(1, 0).Value = TextBox10.Value

If CheckBox4.Value = True Then

Range(“P4”).End(xlDown).Offset(1, 0).Value = “Yes”

Else

Range(“P4”).End(xlDown).Offset(1, 0).Value = “No”

End If

If CheckBox5.Value = True Then

Range(“Q4”).End(xlDown).Offset(1, 0).Value = “Yes”

Else

Range(“Q4”).End(xlDown).Offset(1, 0).Value = “No”

End If

If CheckBox6.Value = True Then

Range(“R4”).End(xlDown).Offset(1, 0).Value = “Yes”

Else

Range(“R4”).End(xlDown).Offset(1, 0).Value = “No”

End If

If CheckBox7.Value = True Then

Range(“S4”).End(xlDown).Offset(1, 0).Value = “Yes”

Else

Range(“S4”).End(xlDown).Offset(1, 0).Value = “No”

End If

If CheckBox8.Value = True Then

Range(“T4”).End(xlDown).Offset(1, 0).Value = “Yes”

Else

Range(“T4”).End(xlDown).Offset(1, 0).Value = “No”

End If

If CheckBox9.Value = True Then

Range(“U4”).End(xlDown).Offset(1, 0).Value = “Yes”

Else

Range(“U4”).End(xlDown).Offset(1, 0).Value = “No”

End If

If CheckBox10.Value = True Then

Range(“V4”).End(xlDown).Offset(1, 0).Value = “Yes”

Else

Range(“V4”).End(xlDown).Offset(1, 0).Value = “No”

End If

Range(“W4”).End(xlDown).Offset(1, 0).Value = TextBox10.Value

Unload Me

End Sub

Private Sub CommandButton2_Click()

TextBox1.Value = ""
TextBox2.Value = ""
ComboBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
TextBox10.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
CheckBox1.Value = False
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
CheckBox5.Value = False
CheckBox6.Value = False
CheckBox7.Value = False
CheckBox8.Value = False
CheckBox9.Value = False
CheckBox10.Value = False

End Sub

Private Sub CommandButton3_click()

Unload Me

End Sub

Private Sub Label18_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub TextBox1_Change()

End Sub

Private Sub TextBox11_Change()

End Sub

Private Sub UserForm_Click()

End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Welcome to the Board!

Look at what this line actually does:
VBA Code:
Range("A4").End(xlDown).Offset(1, 0).Value = TextBox1.Value
It says to start in cell A4, and hit the CTRL+Down arrow button to take you to the next last row with data, then move down one row.
However, if there is no data in column A under row 4, it will take you down to the last possible row in Excel (row 1,048,576) and then try to move down one row from there.
But if you are already in the last possible row, that is impossible (and hence, you get an error!).

See if this methodology works better:
VBA Code:
Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = TextBox1.Value
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,956
Members
449,096
Latest member
Anshu121

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