+ Reply to Thread
Results 1 to 7 of 7

Run an existing macron on all the sheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-03-2021
    Location
    Brussels
    MS-Off Ver
    Microsoft 365
    Posts
    186

    Run an existing macron on all the sheets

    Dear,

    I have the below code on my Excel that is being run by the "Freeze" icon button on the top.

    However, currently it freezes only the data of the sheet "GENERAL"

    I want this macro to freeze the data of ALL the sheets. How could I adjust that?

    'Freeze all the data of all the sheets when clicking on the Freeze Data button
    
    Sub ReplaceFormulasWithValuesAllSheets()
        On Error GoTo ErrorEncountered
        Dim wks As Worksheet
        Dim errorOccurred As Boolean
        Dim confirmFreeze As Integer
        Dim Language As String
    
        Language = ThisWorkbook.Worksheets("GENERAL").Range("I4").Value
    
        If Language = "Fran?ais" Then
            confirmFreeze = MsgBox(ThisWorkbook.Worksheets("VALIDATIONS").Range("AJ2").Value, vbYesNo + vbQuestion, "Confirm Freeze")
        ElseIf Language = "English" Then
            confirmFreeze = MsgBox(ThisWorkbook.Worksheets("VALIDATIONS").Range("AJ3").Value, vbYesNo + vbQuestion, "Confirm Freeze")
        ElseIf Language = "Nederlands" Then
            confirmFreeze = MsgBox(ThisWorkbook.Worksheets("VALIDATIONS").Range("AJ4").Value, vbYesNo + vbQuestion, "Confirm Freeze")
        Else
            ' Add here a msgbox or another way to handle other languages
        End If
    
        If confirmFreeze = vbNo Then
            Exit Sub
        End If
    
        errorOccurred = False
        Application.EnableEvents = False
    
    ExitPoint:
        On Error GoTo 0
        Application.EnableEvents = True
        If errorOccurred Then
            If Language = "Fran?ais" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AK2").Value)
            ElseIf Language = "English" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AK3").Value)
            ElseIf Language = "Nederlands" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AK4").Value)
            Else
                ' Add here a msgbox or another way to handle other languages
            End If
        Else
            If Language = "Fran?ais" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AL2").Value)
            ElseIf Language = "English" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AL3").Value)
            ElseIf Language = "Nederlands" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AL4").Value)
            Else
                ' Add here a msgbox or another way to handle other languages
            End If
        End If
        Exit Sub
    
    ErrorEncountered:
        errorOccurred = True
        Resume ExitPoint
    
    End Sub
    Thanks
    Simon
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Run an existing macron on all the sheets

    untested
    maybe like this
    Dim Language As String
      For Each wks In Sheets
        Language = wks.Range("I4").Value
    '
    '
    '
    Exit Sub
        Next
    '
    '
    '

  3. #3
    Forum Contributor
    Join Date
    12-03-2021
    Location
    Brussels
    MS-Off Ver
    Microsoft 365
    Posts
    186

    Re: Run an existing macron on all the sheets

    Like this?

    'Freeze all the data of all the sheets when clicking on the Freeze Data button
    
    Sub ReplaceFormulasWithValuesAllSheets()
        On Error GoTo ErrorEncountered
        Dim wks As Worksheet
        Dim errorOccurred As Boolean
        Dim confirmFreeze As Integer
        Dim Language As String
    
        For Each wks In Sheets
    
        Language = ThisWorkbook.Worksheets("GENERAL").Range("I4").Value
    
        If Language = "Fran?ais" Then
            confirmFreeze = MsgBox(ThisWorkbook.Worksheets("VALIDATIONS").Range("AJ2").Value, vbYesNo + vbQuestion, "Confirm Freeze")
        ElseIf Language = "English" Then
            confirmFreeze = MsgBox(ThisWorkbook.Worksheets("VALIDATIONS").Range("AJ3").Value, vbYesNo + vbQuestion, "Confirm Freeze")
        ElseIf Language = "Nederlands" Then
            confirmFreeze = MsgBox(ThisWorkbook.Worksheets("VALIDATIONS").Range("AJ4").Value, vbYesNo + vbQuestion, "Confirm Freeze")
        Else
            ' Add here a msgbox or another way to handle other languages
        End If
    
        If confirmFreeze = vbNo Then
            Exit Sub
        End If
    
        errorOccurred = False
        Application.EnableEvents = False
    
        ExitPoint:
          On Error GoTo 0
          Application.EnableEvents = True
          If errorOccurred Then
            If Language = "Fran?ais" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AK2").Value)
            ElseIf Language = "English" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AK3").Value)
            ElseIf Language = "Nederlands" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AK4").Value)
            Else
                ' Add here a msgbox or another way to handle other languages
            End If
          Else
            If Language = "Fran?ais" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AL2").Value)
            ElseIf Language = "English" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AL3").Value)
            ElseIf Language = "Nederlands" Then
                MsgBox (ThisWorkbook.Worksheets("VALIDATIONS").Range("AL4").Value)
            Else
                ' Add here a msgbox or another way to handle other languages
            End If
        End If
        Exit Sub
        Next
    
    ErrorEncountered:
        errorOccurred = True
        Resume ExitPoint
    
    End Sub

  4. #4
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Run an existing macron on all the sheets

    wrong !!
    change this
        Language = ThisWorkbook.Worksheets("GENERAL").Range("I4").Value
    to
        Language = wks.Range("I4").Value

  5. #5
    Forum Contributor
    Join Date
    12-03-2021
    Location
    Brussels
    MS-Off Ver
    Microsoft 365
    Posts
    186

    Re: Run an existing macron on all the sheets

    Your suggestions don't work at all. Please have a look the file!
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Run an existing macron on all the sheets

    sorry buddy ! just I suggest for you . I no know about your file contains many macro.
    But why you don't say what's the problem to understand what happend with you ?
    may be the others members understand & help you.

  7. #7
    Forum Contributor
    Join Date
    12-03-2021
    Location
    Brussels
    MS-Off Ver
    Microsoft 365
    Posts
    186

    Re: Run an existing macron on all the sheets

    I explained the problem in the initial post... please read above, I have a Macro that runs for 1 sheet but I want it to executes itself on ALL sheets...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 02-08-2022, 02:23 PM
  2. dynamic formula to count through existing and new sheets(In google sheets)
    By wlinksanju in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 11-26-2020, 09:16 PM
  3. running a macron multipple times
    By phillyd023 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-29-2019, 11:45 AM
  4. [SOLVED] TO insert new sheets to the right of all existing sheets.
    By Vivek2705 in forum Excel General
    Replies: 4
    Last Post: 02-21-2019, 09:21 AM
  5. [SOLVED] Macron running extremely slow after update to Excel 2016
    By masben in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-08-2016, 11:26 AM
  6. Need help deleting sheets and moving existing sheets down in order
    By MAGICofSeth in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-27-2012, 06:13 PM
  7. Calling non-existing sheets
    By Arcady in forum Excel General
    Replies: 6
    Last Post: 10-29-2009, 08:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1