How To VBA Code To All Worksheets?
Results 1 to 2 of 2

Thread: How To VBA Code To All Worksheets?
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Nov 2013
    Posts
    242
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default How To VBA Code To All Worksheets?

    I am using this code.
    Code:
    Sub CleanUp()
       With ActiveSheet.UsedRange
          .Value = Evaluate("if({1},trim(clean(substitute(" & .Address & ",char(160),"" ""))))")
       End With
        ActiveSheet.UsedRange
    End Sub
    How can I apply it to all worksheets in the active workbook? If there is ever an error it should skip to the next worksheet.

    I'd like to be able to use the general format for furture codes that I may need.

    Thank you!

  2. #2
    Board Regular alansidman's Avatar
    Join Date
    Feb 2007
    Location
    Steamboat Springs
    Posts
    4,883
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How To VBA Code To All Worksheets?

    Code:
    Option Explicit
    
    
    Sub CleanUp()
        Dim ws As Worksheet
        For Each ws In Worksheets
            With ws
                .Value = Evaluate("if({1},trim(clean(substitute(" & .Address & ",char(160),"" ""))))")
            End With
        Next ws
    End Sub
    Let me know if that works for you
    Alan

    Am Yisrael Chai

    Win 10--Office 2019
    When Posting Code, please use code tags.
    How to insert Mcode to Power Query https://excel.solutions/2017/11/powe...te-code-video/


Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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