+ Reply to Thread
Results 1 to 4 of 4

"Replace:=False" Not Working with .Select Function

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-13-2007
    Location
    Central New York
    MS-Off Ver
    Home: 2007, Office: 2010
    Posts
    158

    "Replace:=False" Not Working with .Select Function

    I have the following code that used to (Excel 2003) select any sheet with a tab color that matches the fill color of a certain cell (TabColor in the code).

    Private Sub PrintTabs_Click()
    
      Dim wks As Worksheet
      Dim TabColor As Long
      Dim PrintSheets As String
     
    TabColor = Sheets("_Options_").Range("TabColor").Interior.Color 'Tab Color to Print (Points to a cell with a user defined color)
     
        For Each wks In Worksheets
              If wks.Tab.Color = TabColor Then
                wks.Select False
              End If
        Next wks
      
       ActiveWindow.SelectedSheets.PrintPreview
        
    End Sub

    Now (Excel 2013), it does not select anything at all, unless I remove the "False" after the .Select. I also tried "Replace:=False" with the same results. When anything regarding the "False" is removed, the final result will be that the last sheet that meets the criteria will be selected. I would like all sheets that match the color to be selected.

    Any help would be appreciated.

    Thank you,

    Mark
    Last edited by mgaworecki; 08-02-2016 at 09:48 AM.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: "Replace:=False" Not Working with .Select Function

    Hi,

    You might use an array of sheet names instead.

    Private Sub PrintTabs_Click()
    
        Dim wks                   As Worksheet
        Dim TabColor              As Long
        Dim PrintSheets           As String
        Dim asSheets()            As String
        Dim i                     As Long
    
        i = 0
        TabColor = Sheets("_Options_").Range("TabColor").Interior.Color    'Tab Color to Print (Points to a cell with a user defined color)
        ReDim asSheets(1 To Sheets.Count)
        For Each wks In Worksheets
            If wks.Tab.Color = TabColor Then
                i = i + 1
                asSheets(i) = wks.Name
            End If
        Next wks
        ReDim Preserve asSheets(1 To i)
        Sheets(asSheets).Select
        ActiveWindow.SelectedSheets.PrintPreview
    
    End Sub
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    12-13-2007
    Location
    Central New York
    MS-Off Ver
    Home: 2007, Office: 2010
    Posts
    158

    Re: "Replace:=False" Not Working with .Select Function

    I worked, thank you. I tried an array earlier today (slightly different than yours) and I was getting the same results as I had been. But, I pasted your code into it and it seems to work well.

    Thank you very much,

    Mark

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: "Replace:=False" Not Working with .Select Function

    You're most welcome.

+ 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. [SOLVED] Doing a Find/Replace not working if "replace" text is too large
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-05-2014, 02:52 PM
  2. [SOLVED] Replace TRUE with "1" and FALSE with "0"
    By nsv in forum Excel General
    Replies: 5
    Last Post: 05-09-2012, 02:43 AM
  3. [SOLVED] Disable Run-Time Errors "Application.DisplayAlerts = False" Not Working
    By Punx in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-12-2012, 03:03 PM
  4. Application.Screenupdating=False when "Find&Replace" is used
    By FallingDown in forum Excel General
    Replies: 4
    Last Post: 03-05-2012, 11:48 AM
  5. Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)" not working
    By redders in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2011, 03:52 PM
  6. Replies: 5
    Last Post: 10-12-2010, 06:46 AM
  7. Replies: 7
    Last Post: 05-13-2006, 05:02 PM
  8. Replies: 0
    Last Post: 08-24-2005, 04:05 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