Macro to add date to column

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi there,

Can someone help me write this VBA code please?

In column K (from K9 down) I have dates or blanks. I want to be able to push a button (POST) and if column K has a date in it (ie. isn't blank) then today's date should be entered in column L (L9 down). Once this date is entered in column K, it shouldn't change (ie. tomorrow it shouldn't change to tomorrow's date).

I would like to be able to push this button multiple times but for it not to override any dates already entered in column K.

So if column L = date then enter today's date in column K if K is blank

Thanks very much! :)
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I'm confused.
You said:

if column K has a date in it (ie. isn't blank) then today's date should be entered in column L (L9 down). Once this date is entered in column K, it …

You first said enter date in column L but then said once this date is entered in column K

You said enter date in L not K


And what should happen if column K is empty?
 
Upvote 0
This script will look down column K and if cell is not empty and same cell column L is empty then date will be entered in column L

Code:
Sub Search_For_Date()
'Modified 11/20/2018 12:29:04 AM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "K").End(xlUp).Row
For i = 9 To Lastrow
    If Cells(i, "K").Value <> "" And Cells(i, "L") = "" Then Cells(i, "L").Value = Date
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
My take on this
Code:
Sub AddDate()
   With Range("K9", Range("L" & Rows.Count).End(xlUp).Offset(, -1))
      .Value = Evaluate(Replace(Replace("if(((@l<>"""")*(@="""")),today(),@)", "@l", .Offset(, 1).Address), "@", .Address))
   End With
End Sub
 
Upvote 0
I'm sure this works but I never like using code I do not understand. All this code like * ^ @@ all looks like C programming or greek to me. I like using simple Vba programming where a lot of the code seems to me to be easily understood at least to me.

My take on this
Code:
Sub AddDate()
   With Range("K9", Range("L" & Rows.Count).End(xlUp).Offset(, -1))
      .Value = Evaluate(Replace(Replace("if(((@l<>"""")*(@="""")),today(),@)", "@l", .Offset(, 1).Address), "@", .Address))
   End With
End Sub
 
Upvote 0
Hi MAIT. Thanks very much for the code. It works perfectly!!
Really appreciate it! Thanks again :) :)
 
Upvote 0
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.

Hi MAIT. Thanks very much for the code. It works perfectly!!
Really appreciate it! Thanks again :) :)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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