Make what cell that is selected be the 'active' cell

cdb0ewm

Board Regular
Joined
Aug 11, 2012
Messages
66
I have the simple code below. I would like to be able to run it from any cell in the sheet rather than just B7. I.E. run the same macro from E28 and return the result to E28
Is there an easy way to do this?

Sub Macro2()
Range("B7").Select
ActiveCell.FormulaR1C1 = "=NOW()"
Range("B7").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
 
Last edited:

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

bbott

Well-known Member
Joined
Feb 5, 2010
Messages
2,350
Is this what you're looking for?

Code:
Sub InsertNow()

    ActiveCell.Value = Now
    
End Sub
 
Last edited:

Roderick_E

Well-known Member
Joined
Oct 13, 2007
Messages
2,051
Is this what you're looking for?

Code:
Sub InsertNow()

    ActiveCell.Value = Now
    
End Sub

Or....
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveCell.Value = Now
End Sub
But it's kind of silly since it would simply put the current date and time in cell selected
 

bbott

Well-known Member
Joined
Feb 5, 2010
Messages
2,350
Another thought....if you just want today's date and don't need the time, you can just select a cell and press CTRL+;
 

Watch MrExcel Video

Forum statistics

Threads
1,123,073
Messages
5,599,619
Members
414,325
Latest member
annamsreenu

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
Top