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 fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,215,628
Messages
6,125,900
Members
449,271
Latest member
bergy32204

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