how to skip blank cells that match?

elmnas

Board Regular
Joined
Feb 20, 2015
Messages
206
Hello people I have made following code but I need help to skip the blank cells that matching,




Code:
   Sub Compare()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim r As Long
    Dim m As Long
    Dim s As Long
    Dim n As Long
    
    
    Set ws1 = ActiveSheet
    m = ws1.range("A" & ws1.Rows.Count).End(xlUp).Row
    
    Set ws2 = Worksheets("sheet2")
    n = ws2.range("A" & ws2.Rows.Count).End(xlUp).Row
    
    For r = 1 To m
        For s = 1 To n
        
       
            If ws1.range("A" & r) = ws2.range("A" & s) And _
               ws2.range("B" & r) = ws2.range("B" & s) Then
                
                
                MsgBox ws2.range("A" & s).Text
                Exit For
            End If
        Next s
    Next r
End Sub
Could someone help me?


Thank you in advance
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Code:
 Sub Compare()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim r As Long
    Dim m As Long
    Dim s As Long
    Dim n As Long
    
    
    Set ws1 = ActiveSheet
    m = ws1.range("A" & ws1.Rows.Count).End(xlUp).Row
    
    Set ws2 = Worksheets("sheet2")
    n = ws2.range("A" & ws2.Rows.Count).End(xlUp).Row
    
    For r = 1 To m
        For s = 1 To n
        
       
            If ws1.range("A" & r) = ws2.range("A" & s) And _
               ws2.range("B" & r) = ws2.range("B" & s) Then
                
                [COLOR="#FF0000"]If ws2.range("A" & s).Text <>"" Then[/COLOR]
                MsgBox ws2.range("A" & s).Text
[COLOR="#FF0000"]End If[/COLOR]
                Exit For
            End If
        Next s
    Next r
End Sub
 
Upvote 0
Code:
 Sub Compare()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim r As Long
    Dim m As Long
    Dim s As Long
    Dim n As Long
    
    
    Set ws1 = ActiveSheet
    m = ws1.range("A" & ws1.Rows.Count).End(xlUp).Row
    
    Set ws2 = Worksheets("sheet2")
    n = ws2.range("A" & ws2.Rows.Count).End(xlUp).Row
    
    For r = 1 To m
        For s = 1 To n
        
       
            If ws1.range("A" & r) = ws2.range("A" & s) And _
               ws2.range("B" & r) = ws2.range("B" & s) Then
                
                [COLOR="#FF0000"]If ws2.range("A" & s).Text <>"" Then[/COLOR]
                MsgBox ws2.range("A" & s).Text
[COLOR="#FF0000"]End If[/COLOR]
                Exit For
            End If
        Next s
    Next r
End Sub

Thank you so much!!!
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top