How to add today's date if cell is empty, and if not skip to next column?

Hifty

New Member
Joined
Jun 8, 2021
Messages
10
Office Version
  1. 365
Im a complete VBA noob and im trying to do what seems to be a simple thing.

The purpose of my code is to make a button where it checks to see if the cell is not empty, it should offset to the next column and if it is empty, then it should add todays date.
So each day I press the button it adds a new date next to the old one.

Here is the code I wrote:

Private Sub New_Date_Click()
ActiveSheet.Range("E1").Select
If Not IsEmpty(ActiveCell.Value) Then
ActiveCell.Offset(0,1)
Else
ActiveCell.Value = Date
End Sub

It gives me an error message that an Equal sign is missing on row 4 where the offset is.

The images show what im trying to do.
 

Attachments

  • Help 1.PNG
    Help 1.PNG
    37.6 KB · Views: 50
  • Help 2.PNG
    Help 2.PNG
    24 KB · Views: 48

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
What do you wan to do if E1 is not empty?
 
Upvote 0
What do you wan to do if E1 is not empty?
If E1 is not empty, I want it to check if the cell on its right is empty, so F1. And if F1 is not empty, I want it to check the next one, and so on.
 
Upvote 0
Ok, how about
VBA Code:
Sub New_Date_Click()
   Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Value = Date
End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
Sub New_Date_Click()
   Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Value = Date
End Sub
Wow I was really overthinking it, didnt know some of these functions existed, thanks a bunch!
I'll keep learning VBA!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
There is no such thing as Row A, there is column A & row 1.
 
Upvote 0
my apologies for not clarifying, I mean instead of print the date on A1 then B1 Then C1 then D1 to be A1 , A2, A3 since the date start from Column A and moving down
 
Upvote 0
In that case you can use
Excel Formula:
   Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Date
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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