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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,222,414
Messages
6,165,892
Members
451,992
Latest member
kaurmanjodh

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