Run a macro on the cells a user has highlighted

Sheila Yau

New Member
Joined
Nov 29, 2006
Messages
20
Hi All,

I am trying to adapt this macro so that instead of specifiying the Range("A1:B20") in the macro, it will perform the task on the cells a user has highlighted in the excel worksheet.
This is so they can perform the macro in any cells/worksheets in a workbook.

Sub f2enter()
Dim c As Range
For Each c In Range("A1:B20").Cells
c.Select
SendKeys "{F2}", True
SendKeys "{ENTER}", True
Next
End Sub

Thanks

Sheila
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Code:
Sub f2enter()
Dim c As Range
 
For Each c In Selection
   SendKeys "{F2}", True
   SendKeys "{ENTER}", True
Next c
 
End Sub

Out of interest, what do you aim to achieve by running this code?

edit: you probably know that Excel must be the active application when you run this, i.e. you can't run it from the VB Editor. There's probably a way to test for that.

You might want to add another test to ensure the Selection is a range, rather than an object or a Pivot Table.....
 
Last edited:
Upvote 0
It's to deal with an excel bug we have. The excel workbooks we have (they are quite large and have to be set on manual calc) have linked cell references within the workbook.
When data has been refreshed the links don't always update after F9, a user has to go through each cell and hit F2 + enter.
 
Upvote 0
What about updating the links via the Edit Links dialog box??
 
Upvote 0

Forum statistics

Threads
1,213,539
Messages
6,114,221
Members
448,554
Latest member
Gleisner2

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