Mixed messages

mikecox39

Active Member
Joined
Mar 5, 2014
Messages
251
Office Version
  1. 365
Platform
  1. Windows
I know that [=NOW ()] delivers the current date and time; depending on how the cell is formatted, but that function is dynamic and, if left in the cell, changes over time.


I read somewhere that you can copy the result of that formula the paste it back, as data, to convert it to as static date.


So I tried to create a macro that does that and was successful. However I got a lot of mixed messages in the process.

Is this the easiest way to create a current date and time? I was thinking of using this macro as a kind of Function, that I could "call" from other macros to enter my dates.


https://app.box.com/s/l9ejhyrxoamweuvf649dg9le58iu21zc
 
mike you could also use

Code:
sub test()
    with range("a1")
        .value = now()
        .value = .value
    end with
end sub
Bingo :cool:

Thanks Michael, that's exactly what I was hoping for, clean and simple!

Would you mind explaining how that works? Why with/ end with? Is .value a variable? Why is it pref with a (.)?
 
Last edited:
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
If you only want the current Time put into a cell that is static and will never change and your using Vba to do this I always use:
This puts the value into the cell not a formula so it will never change.

Cells(5, 5).Value = Time
 
Upvote 0
Hey Mike
The with / end with is just a simplication of

Code:
sub test()
   range("a1") .value = now()
   range("a1") .value = range("a1") .value
end sub
Shorter, cleaner, easier to read.....(y)
 
Upvote 0
I normally use With when I want to perform several different task to the same Range

Like this:

Code:
Sub My_With()
'Modified 5/20/2019 3:52:43 AM  EDT
With Cells(1, 1)
    .Value = "Alpha"
    .Font.Size = 16
    .Font.Bold = True
    .Font.Color = vbRed
    .Interior.ColorIndex = 4
End With
End Sub
 
Upvote 0
Yes, date written is non volatile, you're writing in the cell a value (date), not a formula.
 
Last edited:
Upvote 0
Hey Mike
The with / end with is just a simplication of

Code:
sub test()
   range("a1") .value = now()
   range("a1") .value = range("a1") .value
end sub
Shorter, cleaner, easier to read.....(y)
Nice! Thanks
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,843
Members
449,471
Latest member
lachbee

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