Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel VBA

Posted on 2014-02-23
7
Medium Priority
?
369 Views
Last Modified: 2014-02-23
Hello,
can you please help,
I'm using below code to compare sheets Columns and then Delete rows.
right now, I run it one sheet at a time,
can I run this for multiple sheets.

Example
    Set ws1 = Sheets("COM116")
I have sheets
COM58, COM116, COM170,COM135, COM150, COM235 , ..... and more..

Sub TESTTTT()
Sub Compare_Delete()
    Dim i As Long
    Dim iLastRow As Long, xLastRow As Long
    Dim ws As Worksheet, ws1 As Worksheet
     
    Set ws = Sheets("COM1")
    Set ws1 = Sheets("COM116")

     'ws1.Visible = xlSheetVisible
    xLastRow = ws1.Range("A5000").End(xlUp).Row
    With ws
        iLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        For i = iLastRow To 2 Step -1
            For x = xLastRow To 2 Step -1
                If .Cells(i, "A").Value = ws1.Cells(x, "A").Value And _
                .Cells(i, "B").Value = ws1.Cells(x, "B").Value And _
                .Cells(i, "C").Value = ws1.Cells(x, "C").Value And _
                .Cells(i, "W").Value = ws1.Cells(x, "W").Value Then
                    .Rows(i).Delete
                End If
            Next x
        Next i
    End With
End Sub

Any help is appreciated.
thanks
0
Comment
Question by:W.E.B
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 34

Expert Comment

by:Norie
ID: 39880850
What other sheets do you want to compare?
0
 

Author Comment

by:W.E.B
ID: 39880856
Hello,
COM212
COM216
COM222

thanks
0
 
LVL 34

Expert Comment

by:Norie
ID: 39880862
Do you want to compare them to COM1 or to each other?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:W.E.B
ID: 39880866
to COM1
0
 
LVL 34

Accepted Solution

by:
Norie earned 1200 total points
ID: 39880976
Perhaps.
Sub Compare_Delete()
Dim i As Long
Dim iLastRow As Long, xLastRow As Long
Dim ws As Worksheet, ws1 As Worksheet

    Set ws = Sheets("COM1")
    For Each ws1 In ActiveWorkbook.Worksheets

        If ws1.Name Like "COM*" And Not ws1 Is ws Then


            xLastRow = ws1.Range("A5000").End(xlUp).Row
            With ws
                iLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
                For i = iLastRow To 2 Step -1
                    For x = xLastRow To 2 Step -1
                        If .Cells(i, "A").Value = ws1.Cells(x, "A").Value And _
                           .Cells(i, "B").Value = ws1.Cells(x, "B").Value And _
                           .Cells(i, "C").Value = ws1.Cells(x, "C").Value And _
                           .Cells(i, "W").Value = ws1.Cells(x, "W").Value Then
                            .Rows(i).Delete
                        End If
                    Next x
                Next i
            End With
        End If
    Next ws1
    
End Sub

Open in new window

0
 

Author Comment

by:W.E.B
ID: 39881138
Hello,
thank you , this is working,

But,
how do i exclude some sheets that start with COM ?

example,
COM123
COM321

thanks
0
 

Author Closing Comment

by:W.E.B
ID: 39881190
Got it,
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question