I am new on VBA and need help

KingGoku

New Member
Joined
Jul 12, 2023
Messages
31
Office Version
  1. 2016
Platform
  1. Windows
Hi there,

I am getting error on following code. can't seem to get find last row function working. i have tried last row as range and long. please help.
1689725972786.png
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Dim i As Integer
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet
Dim NextRow As Long
Dim LastRow As Long
Dim wsName As String





wsName = FormSelectSht.ComboBoxMachines.Value

For Each ws In wb.Sheets
If ws.Name = wsName Then ws.Activate


LastRow = ws.Cells("A", Rows.Count).End(xlUp).Row



Next








'Find Last row
'LastRow = ws.Cells.Find("*", [A4], , , xlByRows, xlPrevious).Row




'Find next empty row to enter data

NextRow = LastRow + 1

'énter data into active sheet
ws.Range("A" & NextRow) = Date
ws.Range("B" & NextRow) = FormSelectSht.ComboBoxProduct.Value
'ws.Range("C" & NextRow) = juliandt
ws.Range("D" & NextRow) = FormSelectSht.TextBoxOperator1.Value
ws.Range("E" & NextRow) = FormSelectSht.TextBoxOperator2.Value
ws.Range("F" & NextRow) = FormSelectSht.TextBoxLot.Value


End Sub
 
Upvote 0
Your syntax for Cells is the wrong way around. It should be
VBA Code:
LastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
 
Upvote 0
You're welcome. Glad to help. Thanks for the follow-up. (y)

Another option is to use RANGE instead of Cells, then the column does come first. :)

VBA Code:
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,217,058
Messages
6,134,338
Members
449,868
Latest member
danielbryant4

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