F2 + Enter Macro

The Great Dane

New Member
Joined
Dec 6, 2021
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hi all,

I’m new to this so forgive me -

I need a macro to automatically F2 and Enter on one cell for each tab (Cell A1). The reason I ask is that I have a working macro that renames each tab based on the contents of this cell, A1. However to activate the change in tab name I have to click into A1 and enter for the change to take place - I want this to be automatic.

Thanks,
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
so, by tab do you mean "worksheet tabs" and also, what is your piece of code?
 
Upvote 0
Hi & welcome to MrExcel.

However to activate the change in tab name I have to click into A1 and enter for the change to take place
This sounds like a chicken and egg story: what came first?

So what comes first, changing cell A1 or changing the name of your worksheet?
Imo you don't need a "F2 & Enter" approach. Tell us exactly what you want and supply the code you already have.
 
Upvote 0
Hi both,

Thanks for the fast replies.

I can’t share the cut and paste code but I have written it here:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target,Range(“A1”)) Is Nothing Then
ActiveSheet.Name=ActiveSheet.Range(“A1”)
End if
End Sub

The idea is that A1 updates based on a data sample (so this is a formula inside A1) so once the dataset is inserted, A1 would change, then the macro triggers the worksheet name to change as currently the worksheet name does not update unless I physically go into A1 each time.

To answer your question, I’m guessing the change in A1 comes first? I’m very new to macros so apologies - I hope the above is clear?

Thanks,
 
Upvote 0
I see. You're using the worksheet change event handler, which will not fire when a formula evaluates to another value. The Calculate event does.

The code below goes in the module of the worksheet to be affected.
Note there's no guard clause in case the intended new worksheet name contains invalid characters, like /?*:[]\

VBA Code:
Private Sub Worksheet_Calculate()
    If Me.Range("A1").Value <> Me.Name Then
        Me.Name = Me.Range("A1").Value
    End If
End Sub
 
Upvote 0
Solution
You are welcome and thanks for letting me know (y)
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,836
Members
449,096
Latest member
Erald

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