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:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Is this what you're looking for?

Code:
Sub InsertNow()

    ActiveCell.Value = Now
    
End Sub
 
Last edited:
Upvote 0
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
 
Upvote 0
Another thought....if you just want today's date and don't need the time, you can just select a cell and press CTRL+;
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,174
Members
449,071
Latest member
cdnMech

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