Results 1 to 4 of 4

If sh.name=Ws.name issue

Threaded View

  1. #1
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    If sh.name=Ws.name issue

    A previous thread I answered, I was looping through the sheets, and if the sh.name<>w1.name or sh.name<>w2.name or sh.name<>w3.name then

    The code would not ignore the w1,w2,w3 worksheets, I had to use if then for each worksheet.

    If Or code
    Sub MakeItSo()
        Dim w1 As Worksheet, w2 As Worksheet, w3 As Worksheet
        Dim lastColumn As Long, sh As Worksheet, s As String
        Dim lastRow As Long
        Dim rng As Range
    
        Set w1 = Sheets("Group1")
        Set w2 = Sheets("Group2")
        Set w3 = Sheets("Group3")
    
        For Each sh In Sheets
            If sh.Name <> w1.Name Or sh.Name <> w2.Name Or sh.Name <> w3.Name Then
                s = Left(sh.Name, 1)
                With sh
                    lastColumn = .Cells(1, Columns.Count).End(xlToLeft).Column
                    lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
                    Set rng = .Range(.Cells(1, 1), .Cells(lastRow, lastColumn))
                    rng.Copy Sheets("Group" & s).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
                End With
            End If
    
        Next sh
    End Sub
    If then Code
    Sub MakeItSeveralIfs()
        Dim w1 As Worksheet, w2 As Worksheet, w3 As Worksheet
        Dim lastColumn As Long, sh As Worksheet, s As String
        Dim lastRow As Long
        Dim rng As Range
    
        Set w1 = Sheets("Group1")
        Set w2 = Sheets("Group2")
        Set w3 = Sheets("Group3")
    
        For Each sh In Sheets
            If sh.Name <> w1.Name Then
                If sh.Name <> w2.Name Then
                    If sh.Name <> w3.Name Then
                        s = Left(sh.Name, 1)
                        With sh
                            lastColumn = .Cells(1, Columns.Count).End(xlToLeft).Column
                            lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
                            Set rng = .Range(.Cells(1, 1), .Cells(lastRow, lastColumn))
                            rng.Copy Sheets("Group" & s).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
                        End With
                    End If
                End If
            End If
        Next sh
    End Sub
    I'm sure I have gotten this to work before.

    Check out the attached.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Insert shift down issue macro issue
    By CC64 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-15-2012, 10:57 PM
  2. Issue with X axis values NOT graphing on Scatter graph and issue with Labels
    By lmausolf in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2012, 07:20 AM
  3. Issue - Image button issue - by JBeaucaire
    By Vaibhav in forum Suggestions for Improvement
    Replies: 2
    Last Post: 05-06-2012, 07:35 AM
  4. [SOLVED] Issue - Attachment issue - by Simon Lloyd
    By Vaibhav in forum Suggestions for Improvement
    Replies: 16
    Last Post: 03-16-2012, 06:56 PM
  5. [SOLVED] Issue -Joke thread issue - Mordred
    By Vaibhav in forum Suggestions for Improvement
    Replies: 2
    Last Post: 02-17-2012, 01:31 PM

Tags for this Thread

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