Simple FOR/IF combination

oggy3000

Board Regular
Joined
Jul 13, 2011
Messages
51
Hello,
I have a small problem with an For/If combination.
The macro is supposed to check the Data sheet for 2 criteria but its not working the way I want it to. Basically I don't know how to tell the macro to count/go on if not both IF statements are true.

Thank you

Code:
        For icount = 2 To lngDrange
            If Worksheets("Data").Cells(icount, 5) = cboPc.Value Then
                If Worksheets("Data").Cells(icount, 2) = lngLJH Then
                    wks2.Range("A" & lngRange & ":F" & lngRange).Copy Destination:=wks1.Cells(lngTlast, 1)
                    wks1.Cells(lngTlast, 7) = Me.txtLjh.Value
                    wks1.Cells(lngTlast, 7).NumberFormat = "General"
                    Exit For
                End If
            End If
        Next icount
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi.
Try changing the end's around

Code:
For icount = 2 To lngDrange
            If Worksheets("Data").Cells(icount, 5) = cboPc.Value Then
                If Worksheets("Data").Cells(icount, 2) = lngLJH Then
                    wks2.Range("A" & lngRange & ":F" & lngRange).Copy Destination:=wks1.Cells(lngTlast, 1)
                    wks1.Cells(lngTlast, 7) = Me.txtLjh.Value
                    wks1.Cells(lngTlast, 7).NumberFormat = "General"
                                    End If
            End If
Exit For

        Next icount
also do you want it to continue once it matches or stop?
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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