VBA: How to change cell value in another sheet based on the active sheet

davey4444

Board Regular
Joined
Nov 16, 2010
Messages
97
Hi there,

I think that my thread title sums it up but essentially all that I want to do is to change the value of cell A1 in Sheet1 to whatever my active sheet is in the same workbook. Ideally I would like this to update automatically whenever I change sheets however if a button on every other sheet is needed then I can live with that.

Thanks.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Not sure I understand your request. You want Sheet1 cell A1 value to be the same as cell A1 of the active sheet or ...?
 
Upvote 0
Thanks for the quick reply. Essentially I would like A1 in Sheet1 to hold the value of whatever Active Sheet I am in i.e the name of the active sheet rather than the value of any cell within it.
 
Upvote 0
I am not sure if you want sheet1 to reflect if its the active sheet
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If ActiveSheet.Name <> "Sheet1" Then
        Sheet1.Range("A1").Value = ActiveSheet.Name
    End If
End Sub

or without the if (applies to all sheets including sheet1)
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
          Sheet1.Range("A1").Value = ActiveSheet.Name
End Sub
 
Last edited:
Upvote 0
Thanks for the quick reply. Essentially I would like A1 in Sheet1 to hold the value of whatever Active Sheet I am in i.e the name of the active sheet rather than the value of any cell within it.
See post #4 from Momentman.
 
Upvote 0

Forum statistics

Threads
1,214,581
Messages
6,120,368
Members
448,957
Latest member
BatCoder

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