Forum

After a macro paste...
 
Notifications
Clear all

After a macro pastes a cell with the =NOW() date function from an invoice sheet into a report sheet, how do I keep the original pasted date?

5 Posts
3 Users
0 Reactions
69 Views
(@briangee)
Posts: 3
Active Member
Topic starter
 

This is the code I am using:

Sheets("Invoice").Select
Range("B12").Select
Selection.Copy
Sheets("Report").Select
erow = Sheet3.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 5).Offset(-1, 0).Select
ActiveSheet.Paste

 
Posted : 04/05/2019 10:46 am
Philip Treacy
(@philipt)
Posts: 1632
Member Admin
 

Hi Brian,

The code you pasted doesn't have any call to NOW() in it?

If you are calling NOW() from your macro then just check that the cell where the result from NOW() goes isn't blank, and don't call NOW() again :

 

   If Range("A1") = "" Then

      Range("A1") = Now()

   End If

 

Regards

Phil

 
Posted : 07/05/2019 7:55 am
(@briangee)
Posts: 3
Active Member
Topic starter
 

Thanks kindly Phil, my apologies for the confusion I caused!

I have built an Excel invoice system that creates an invoice record for every client, saves it with that invoice number, then adds +1 to the invoice number & clears the form to ready it for the next client.

Just after the invoice saves in macro1, it copies & pastes certain fields of the invoice {for accounting purpose} in macro2, and places those cells into sheet3.

When it copies cell ("B12") which uses the =NOW() formula, it pastes it as the =NOW() formula {despite me not specifying to paste the actual value} so if you go into the report the next day, it displays the invoice date as that present day, not the original date of yesterday.

I am looking to add a command in the step2 macro to ensure the report date of that invoice record stays the same as the date it is posted.

Thanks very much for your help!!

 
Posted : 08/05/2019 8:42 am
(@debaser)
Posts: 838
Member Moderator
 

Replace all the code you posted with this:

With Sheet3
erow = .Cells(.Rows.Count, 1).End(xlUp).Row
.Cells(erow, 5).Value = Sheets("Invoice").Range("B12").Value
End With
 
Posted : 08/05/2019 9:09 am
(@briangee)
Posts: 3
Active Member
Topic starter
 

Thankyou!

 
Posted : 09/05/2019 8:08 am
Share: