0

I am dealing with VBA for the first time and am having trouble figuring out what is wrong with this method:


Private Sub NewProductButton_Click()

'Find the first empty row in the Products sheet

Dim inputcell As Long, lastcell As Long
inputcell = Products.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
lastcell = Products.Cells(Rows.Count, 1).End(xlUp)
'Submit form data to the sheet
Cells(inputcell, 1) = lastcell + 1
Cells(inputcell, 2) = ProdNameBox
Cells(inputcell, 3) = ProdTypeComboBox
Cells(inputcell, 4) = PrepTimeBox
Cells(inputcell, 5) = CostBox
Cells(inputcells, 6) = PriceBox
'Clear the form
Me.ProdNameBox.Value = ""
Me.ProdTypeComboBox.Value = ""
Me.PrepTimeBox.Value = ""
Me.CostBox.Value = ""
Me.PriceBox.Value = ""

End Sub

This method is supposed to enter the data into the first empty row of the sheet (from a form). The debugger highlights inputcell = Products.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row and throws the error. Any help will be appreciated!

2
  • 1
    Add Option Explicit to the top of your module. This will help you locate the source of the error Commented Apr 26, 2014 at 1:08
  • 1
    @chrisneilsen is right. What he's trying to say is declare your variables. It is easier to debug codes with properly declared variables Commented Apr 26, 2014 at 3:47

1 Answer 1

1

Im assuming that Products is the name of the sheet. If that is the case you need to use:

inputcell = Sheets("Products").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
lastcell = Sheets("Products").Cells(Rows.Count, 1).End(xlUp) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.