Rename sheets 2 times from name from another shhet by vba

KlausW

Active Member
Joined
Sep 9, 2020
Messages
458
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone I have a challenge naming tabs that I import into a sheet. The tab in which the name appears is called VPL, in column E there are names of the employees, and that is the name of the tabs that I import as well. In column B I insert a number, and now the tabs must change to the number to the left of the name. Example tje name Peter is in E5 and so is the sheet called Now I write 4205 in B5, the sheet name Peter must also be renamed to 4205. Later I write 199 in A5, the sheet 4205 must also be renamed to 199. There are about 50 Tabs. Does it make sense. Any help will be appreciated. Best Regards Klaus W
 
With the first code disabled and the second code in the VPL sheet's code pane, second code should happily be run from a button within the VPL sheet?
It just requires that at the time of running it, a cell in the relevant row in VPL sheet is selected.
It needs that, or some by some other means to know which row it is referring to for data.
The first code knows which row because it is because it is associated/triggered by the Change Event.
Hi Snakehips Im on work in Greenland right now and the net is terribal. So I replay ASAP it return to normale. Regards Klaus W
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Når den første kode er deaktiveret og den anden kode i VPL-arkets koderude, skal anden kode med glæde køres fra en knap i VPL-arket?
Det kræver bare, at der på tidspunktet for kørsel vælges en celle i den relevante række i VPL-ark.
Det har brug for det, eller på anden måde for at vide, hvilken række det henviser til for data.
Den første kode ved hvilken række, fordi den skyldes, at den er tilknyttet/udløst af ændringshændelsen.

With the first code disabled and the second code in the VPL sheet's code pane, second code should happily be run from a button within the VPL sheet?
It just requires that at the time of running it, a cell in the relevant row in VPL sheet is selected.
It needs that, or some by some other means to know which row it is referring to for data.
The first code knows which row because it is because it is associated/triggered by the Change Event.
I would like to have a button that I can press, also the VBA code should run
 
Upvote 0
Hi Klaus.
I'm not entirely sure what your method of working is but this might help?
VBA Code:
Sub ReNameTab()
Dim NewName As String
Dim OldName As String
Dim Rw As Integer
Rw = Selection.Row  '***Assumes cell within relevant row in VPL will be selected?????

'If A has value, rename Tab B as  A
If Len(Cells(Rw, 1).Text) > 1 Then
    OldName = Cells(Rw, 2)
    NewName = Cells(Rw, 1)
    GoTo DoStuff
Else
'Otherwise If B has value, rename Tab E as B
If Len(Cells(Rw, 2).Text) > 1 Then
    OldName = Cells(Rw, 5)
    NewName = Cells(Rw, 2)
End If
End If

DoStuff:
On Error Resume Next  ' ignore if sheet name cannot be found
'Change tab name
Sheets(OldName).Name = NewName
On Error GoTo 0  ' reset default error handling
End Sub
As it stands, it is reliant upon having a cell within the appropriate row of VPL selected at the time of running.
Hi Snakehips working as it should, thanks a lot. I will make a new question, on the one with the button. Best regards Klaus W
 
Upvote 0
Hi Snakehips working as it should, thanks a lot. I will make a new question, on the one with the button. Best regards Klaus W
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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