Automating Sheet name from value in Cell

itisananas

New Member
Joined
Jul 12, 2021
Messages
9
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hey people!I came here againg to ask for your help.
So my goal is to make a button and link the button press with the macro NieuweVersieKaartBe.
The goal from the macro is to copy current sheet and paste it into another and then just update the names Be V(number).

Is there a easier way to change the Be V2 to a value from a cell. So That it can read Be V2 or Be V3 from a cell instead.

Sheets("Be V2").Select

If you are wondering why there are numbers from 10 to 2. Thats a sertain value i linked to the amount of Be V# versions that are already made



VBA Code:
Sub NieuweVersieKaartBe()

'Dit moet de Controllekaarten versies verversen alleen werkt het nog niet echt
TabbladenTeller

'Alle Berekeningen in Excel uitzetten

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False

   
    'Hier komt een venster met een bevestiging voor het aan maken van een nieuwe nummer
    Dim answer As Integer
   
    answer = MsgBox("Door op 'ja' te klikken wordt er een nieuwe versie nr. aangemaakt", vbQuestion + vbYesNo + vbDefaultButton2, "Aanvraag nieuwe Versie nr.")
   
    'als het antwoord Ja is op de venster maak dan nieuwe versie aan
    If answer = vbYes Then
   
        With Sheets("Controllekaarten Versie Teller").Range("G4")
           
            If .Value = 10 Then
           
               
           
            ElseIf .Value = 9 Then
           
                           
       
            ElseIf .Value = 8 Then
           
                           
       
            ElseIf .Value = 7 Then
           
               
       
            ElseIf .Value = 6 Then
           
               
                   
            ElseIf .Value = 5 Then
           
       
       
            ElseIf .Value = 4 Then
           
               
       
            ElseIf .Value = 3 Then
           
                Sheets("Be V2").Select
               
                ActiveSheet.Name = "Be V3"
                Sheets("Be V3").Copy Before:=Sheets("Be V3")
                ActiveSheet.Name = "Be V2"
               
                MacroBeV3
               
                With Sheets("Be V2").Range("F1066")
                    Sheets("Be V2").Select
                    If .Value > 0 Then
                    Sheets("Be V2").Range("A" & .Value).Select
                    End If
                    Selection.Value = "x"
                End With
               
                Sheets("Be V3").Select
                Sheets("Be V3").Range("A22:A1021").Clear
                Range("A19").Select
               
                MsgBox "Be V3 is aangemaakt"
                              
       
            ElseIf .Value = 2 Then
           
                Sheets("Be V1").Select
    
                ActiveSheet.Name = "Be V2"
                Sheets("Be V2").Copy Before:=Sheets("Be V2")
                ActiveSheet.Name = "Be V1"
               
                MacroBeV2
               
                With Sheets("Be V1").Range("F1066")
                    Sheets("Be V1").Select
                    If .Value > 0 Then
                    Sheets("Be V1").Range("A" & .Value).Select
                    End If
                    Selection.Value = "x"
                End With
               
                Sheets("Be V2").Select
                Sheets("Be V2").Range("A22:A1021").Clear
                Range("A19").Select
               
                MsgBox "Be V2 is aangemaakt"
           
           
            End If
   
        End With

    'als het antwoord NEE is op de venster dan annuleer deze aanvraag
    ElseIf answer = vbNo Then
    MsgBox "Aanvraag is geannulleerd"
   
    End If
   
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
   
End Sub

EDIT: sorry i forgot to add MacroBeV2/3

VBA Code:
Sub MacroBeV2()
'
' MacroBeV2
'

'
    Sheets("Be V1").Select
    Range("B1024:B1063").Select
    Application.CutCopyMode = False
    Selection.Copy
    
    Sheets("Be V2").Select
    Range("B22").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False


End Sub


VBA Code:
Sub MacroBeV3()
'
' MacroBeV3
'

'
    Sheets("Be V2").Select
    Range("B1024:B1063").Select
    Application.CutCopyMode = False
    Selection.Copy
    
    Sheets("Be V3").Select
    Range("B22").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False


End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
What cell is the name that you want in?
If it was in, say cell C1, then the code would just look like:
VBA Code:
ActiveSheet.Name = Range("C1")
 
Upvote 0
What cell is the name that you want in?
If it was in, say cell C1, then the code would just look like:
VBA Code:
ActiveSheet.Name = Range("C1")
Wel your answer is like half of what i want. Can "Be V#" be replaced in every part of the code to be the cell value C1. That will be more accurate i think
 
Upvote 0
If you are trying to make it dynamic throught your code, you can do it by creating a sheet name variable, i.e.
VBA Code:
Dim sname as String
sname = Range("C1")

'Name active sheet
ActiveSheet.Name = sname

'Refer to sheet in code
Sheets(sname).Select
 
Upvote 0
Solution
If you are trying to make it dynamic throught your code, you can do it by creating a sheet name variable, i.e.
VBA Code:
Dim sname as String
sname = Range("C1")

'Name active sheet
ActiveSheet.Name = sname

'Refer to sheet in code
Sheets(sname).Select
Thank you so much this worked! :D
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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