Date stamp vba

pete4monc

Board Regular
Joined
Jan 12, 2014
Messages
85
Office Version
  1. 365
Platform
  1. Windows
I have a vba which inserts a date in the selected cell and it works by clicking a command button but it is a long process clicking in each cell, clicking the button and then moving down to the next cell etc.

Sub timeStamp()

Dim ts As Date

With Selection

.Value = Now

.NumberFormat = "m/d/yyyy"

End With

End Sub

I would like to automate the process so whenever I click the button it updates- if there is text in B2 it must date stamp C2 and continue until there is no more text in column "B".
But the next day I input data into column B it must not overwrite the date in column C but start the date in the first empty cell in column C.

Thanks for your help.

Pete
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hello Pete4monc,
do you mean something like this...
VBA Code:
Sub TimeStamp()

    Dim vNB As Long, vNC As Long, _
        vN As Long, vN2 As Long
    Dim ts As Date
   
    With ActiveSheet
        vNB = .Cells(Rows.Count, "B").End(xlUp).Row
        vNC = .Cells(Rows.Count, "C").End(xlUp).Row
        vN2 = vNB - vNC
        For vN = 1 To vN2
            If .Cells(vNC + vN, 2) <> "" Then
                With .Cells(vNC + vN, 3)
                    .Value = Now
                    .NumberFormat = "m/d/yyyy"
                End With
            End If
        Next vN
    End With

End Sub
 
Upvote 0
Could be done without looping if the column C is already formated as Date …​
Anyway another beginner starter looping demonstration :​
VBA Code:
Sub Demo1()
    With [A1].CurrentRegion.Columns
            B = .Item(2).Value2
            C = .Item(3).Value
        For R& = 2 To .Rows.Count
            If B(R, 1) > "" And C(R, 1) = 0 Then C(R, 1) = Date
        Next
            .Item(3).Value = C
    End With
End Sub
 
Upvote 0
Sweet, but if in the column "B" are some blank cells maybe can be used something similar like this...
VBA Code:
Sub Demo2()

    Dim vN As Long, vN1 As Long

    vN = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
    With ActiveSheet.Range("B1:B" & vN)
         For vN1 = 1 To vN
             If .Item(vN1).Value > "" Then _
                .Item(vN1).Offset(0, 1).Value = Date
         Next vN1
    End With

End Sub
 
Last edited:
Upvote 0
Solution
No matters until the initial post well describe the context which is lacking here​
so yes sample for smart worksheet but as a starter it can be easily amended with UsedRange for example.​
And with a clever worksheet design no need to loop but as guessing can't be coding …​
 
Upvote 0
This part of request sounds confusing.
"...and continue until there is no more text in column "B" ..."
You are right - "Guessing can't be coding".(y)
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,539
Members
449,038
Latest member
Guest1337

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