I need to enter a 1 when a button is clicked

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,392
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a table and as new rows get added, I need some vba code to enter a 1 into the column AB on the new row. Can someone help me with the syntax please? The table is located on a sheet called "home" and is called tblCosting. There are things below the table, so you can't use the xlup method of finding the last row.

Thanks,
Dave
 
The xlup method of finding the last row won't work as there are things under the table.
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I meant that from the code you provided me with won't work:

Code:
Dim lr As Long


  lr = Worksheets("home").ListObjects("tblCosting").Range.Cells(Rows.Count, 1).End(xlUp).Row

The table begins in A5 and there are things above and below it, so I can't use the xlup method.
This is the code I am trying to work with now.

Code:
Private Sub cmdEnterActivities_Click()
Worksheets("home").Unprotect Password:="costings"

Dim sht As Worksheet
Dim lr As Long

Set sht = Worksheets("Home")

'Find last row using table range
  'lr = sht.ListObjects("tblCosting").Range.Rows.Count
'lr = sht.Range("A5").CurrentRegion.Rows.Count
    Set lr = Worksheets("home").ListObjects("tblCosting").Range.Cells(5, 1).End(xlDown).Row
 
    Worksheets("home").Cells(lr, 29) = txtActivities.Value
'Worksheets("home").Protect Password:="costings"

End Sub

I was thinking the xldown method but I am not sure of the syntax.
I thought I should use column A for the xldown as it is the date and will always be used.

The activities figure needs to be put in column AC of the row being entered. Could you help please?

I was also wondering if there would be a way to enter the activities figure to any row?

Thanks,
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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