Hi there.
Looking for help with vb script that inserts data to 3 different worksheets using an userform with a commandbutton_click.
Found a script (non AI) LastRow that works for the first worksheet (Guests), but for the other sheets Diver Details and Book and Travel it will put the entered data not on the same row if the first column of these sheets is empty.
Have tried different solutions, Dim i As Long, Dim LastRow1 As Long andRange("A" & LastRow + 1) etc., but the empty cells in previous rows still got filled out or were overwritten.
There are so many lastrow questions, but none addressed mine.
Here is the code
Hope that there is someone who can help me with this dilemma and that I have provided enough info to solve this.
Looking for help with vb script that inserts data to 3 different worksheets using an userform with a commandbutton_click.
Found a script (non AI) LastRow that works for the first worksheet (Guests), but for the other sheets Diver Details and Book and Travel it will put the entered data not on the same row if the first column of these sheets is empty.
Have tried different solutions, Dim i As Long, Dim LastRow1 As Long andRange("A" & LastRow + 1) etc., but the empty cells in previous rows still got filled out or were overwritten.
There are so many lastrow questions, but none addressed mine.
Here is the code
VBA Code:
Sub CommandButton1_Click()
'Declare variables
Dim wsGuests As Worksheet
Dim wsDiverdetails As Worksheet
Dim wsBookTravel As Worksheet
Dim LastRow As Long
'Set worksheets
Set wsGuests = ThisWorkbook.Sheets("Guests")
Set wsDiverdetails = ThisWorkbook.Sheets("Diver details")
Set wsBookTravel = ThisWorkbook.Sheets("Book and Travel")
LastRow = Guests.Cells(ws1.Rows.Count, "A").End(xlUp).Row
wsGuests.Cells(LastRow + 1, 1).Value = Me.tbFirst_name.Value
wsGuests.Cells(LastRow + 1, 2).Value = Me.tbLast_name.Value
etc.
LastRow = wsDiverdetails.Cells(ws2.Rows.Count, "A").End(xlUp).Row
wsDiverdetails.Cells(LastRow + 1, 1).Value = Me.tbCert_level.Value
wsDiverdetails.Cells(LastRow + 1, 2).Value = Me.tbNod.Value
etc.
LastRow = wsBookTravel.Cells(ws2.Rows.Count, "A").End(xlUp).Row
wsBookTravel.Cells(LastRow + 1, 1).Value = Me.tbDep_date.Value
wsBookTravel.Cells(LastRow + 1, 2).Value = Me.tbLeave_date.Value
etc.
End Sub