Vba Could not find the specified object

djossh

Board Regular
Joined
Jul 27, 2009
Messages
243
Hi. I have this code below but i'm getting "Could not find the specified object" (error on Me.Controls)
please help. thanks

Private Sub CommandButton1_Click()
Dim i As Long
Dim LastRow As Object


For i = 0 To 21
Set LastRow = Sheet4.Range("a65536").End(xlUp)

LastRow.Offset(1, 0).Value = sino.Value
LastRow.Offset(1, 1).Value = brgyname.Value
LastRow.Offset(1, 2).Value = tin.Value
LastRow.Offset(1, 3).Value = address.Value
LastRow.Offset(1, 4).Value = sidate.Value
LastRow.Offset(1, 5).Value = Me.Controls("qt" & i).Value
LastRow.Offset(1, 6).Value = Me.Controls("unit" & i).Value
LastRow.Offset(1, 7).Value = Me.Controls("desc" & i).Value
LastRow.Offset(1, 8).Value = Me.Controls("up" & i).Value
LastRow.Offset(1, 9).Value = Me.Controls("amt" & i).Value

Next i


End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I think this:
Dim LastRow As Object

Should be this:
Dim LastRow As Long

And I always use this:

Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row




 
Last edited:
Upvote 0
Double check the control names to make sure they correspond to "qt" & i, "unit" & i etc ...

Also remember that le for next loop start at i=0 which means that the first call to Me.Controls("qt" & i).Value will evaluate to Me.Controls("qt0") which I very much suspect is the problem.
 
Upvote 0
Double check the control names to make sure they correspond to "qt" & i, "unit" & i etc ...

Also remember that le for next loop start at i=0 which means that the first call to Me.Controls("qt" & i).Value will evaluate to Me.Controls("qt0") which I very much suspect is the problem.

Thank you. you are correct that "0" was the main problem... God Bless
 
Upvote 0

Forum statistics

Threads
1,214,872
Messages
6,122,026
Members
449,061
Latest member
TheRealJoaquin

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