Macro

G

GEdwards

Cell A1 = blank
Cell A2 is â€
=CONCATENATE(RIGHT(YEAR(NOW()),2),TEXT(MONTH(NOW()),â€00â€),TEXT(DAY(NOW()),â€00â€),TEXT(HOUR(NOW()),â€00â€),TEXT(MINUTE(NOW()),â€00â€),TEXT(SECOND(NOW()),â€00â€))

(results in yymmddhhmmss)

I need a macro or something that when A1 = blank, then I want the resulting
value from A2 to be put into A1. I DO NOT want the formula copied from A2.

What do I need to do to get the resulting value from A2 into A1?
 
O

OssieMac

Hi,

To insert the following code, right click the worksheet tab name, select
View Code and then copy the code below and paste it into the VBA editor.
Close the editor by clicking the X with red background top right of VBA
editor screen.

The code will test A1 each time the worksheet recalculates but will only
update A1 if it is blank.


Private Sub Worksheet_Calculate()

If IsEmpty(Range("A1")) Then
Range("A1") = Range("A2")
End If

End Sub


Also your formula can be modified to a much simpler one.

=TEXT(NOW(),"yymmddhhmmss")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top