Reputation: 23
I am very new to VBA Scripts. I have been googling trying to figure out how to combine these together and assign a button to run this.
My first script I am adding a sequence number and row to a table. The table is two columns B:C. My numbering is looking at the row below the line I am inserting to keep the numbers in sequential order. (I found this on Youtube works great)
Private Sub CommandButton2_Click()
Sheets("Sheet1").Range("B4").Select
ActiveCell.EntireRow.Insert Shift:=xlDown
Sheets("Sheet1").Range("B4:C4").Select
Selection.Borders.Weight = xlThin
Sheets("Sheet1").Range("B4").Select
ActiveCell.Value = "=B5+1"
End Sub
Second one is applying a timestamp to C4 which is giving a timestamp to the sequential number.
Private Sub timeStamp()
Dim ts As Date
With Range("C4")
.Value = Now
.NumberFormat = "h:mm:ss AM/PM"
End With
End Sub
I cannot figure out how to make these two run together. Individually they work.
Thank you in advance for any help.
Upvotes: 1
Views: 206
Reputation: 3670
How about you just paste the code of the second in the first (and a few other adjustments):
Private Sub CommandButton2_Click()
Dim ts As Date
With ThisWorkbook.Sheets("Sheet1")
.Range("B4").EntireRow.Insert Shift:=xlDown
.Range("B4:C4").Borders.Weight = xlThin
.Range("B4").Value= "=B5+1"
With .Range("C4")
.Value = Now
.NumberFormat = "h:mm:ss AM/PM"
End With
End With
End Sub
Upvotes: 1