Help with VBA coding please :)

jedibrown

Board Regular
Joined
Oct 17, 2011
Messages
136
Good morning,

I wondered if somebody could help me.

I have the following code but I need to work out how to put each variable on another line - I can't figure it out. So each "or/and" combination I want on a seperate line.

Private Sub CommandButton1_Click()
Dim LR As Long, i As Long
Sheets("Sheet2").UsedRange.ClearContents
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If Not IsError(Range("A" & i)) Then
If LCase(Range("C" & i).Value) <> "complete" And _
LCase(Range("C" & i).Value) <> "rejected-nonissue" And _
(InStr(LCase(Range("F" & i).Value), "compensation payment") > 0 And InStr(LCase(Range("M" & i).Value), "kh") > 0 Or InStr(LCase(Range("F" & i).Value), "compensation payment") > 0 And InStr(LCase(Range("M" & i).Value), "gd") > 0 Or InStr(LCase(Range("F" & i).Value), "compensation payment") > 0 And InStr(LCase(Range("M" & i).Value), "tb") > 0 Or InStr(LCase(Range("F" & i).Value), "compensation payment") > 0 And InStr(LCase(Range("M" & i).Value), "kc") > 0 Or InStr(LCase(Range("F" & i).Value), "compensation payment") > 0 And InStr(LCase(Range("M" & i).Value), "tg") > 0 Or InStr(LCase(Range("F" & i).Value), "compensation payment") > 0 And InStr(LCase(Range("M" & i).Value), "gr") > 0 Or InStr(LCase(Range("F" & i).Value), "compensation payment") > 0 And InStr(LCase(Range("M" & i).Value), "js") > 0 Or InStr(LCase(Range("F" & i).Value), "compensation payment") > 0 And InStr(LCase(Range("M" & i).Value), "sc") > 0) _
Then Rows(i).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
End Sub
 
Good point, you probably want the tests on raw data as well

Code:
Private Sub CommandButton1_Click()Dim LR As Long, i As Long

    Sheets("Sheet2").UsedRange.ClearContents
    
    With Worksheets("raw data")
    
        LR = .Range("A" & Rows.Count).End(xlUp).Row
        For i = 1 To LR
        
            If Not IsError(.Range("A" & i)) Then
            
                If LCase(.Range("C" & i).Value) <> "complete" And _
                    LCase(.Range("C" & i).Value) <> "rejected-nonissue" And _
                    Year(.Range("K" & i).Value) = 2012 And Month(.Range("K" & i).Value) = 1 And _
                    InStr(LCase(.Range("F" & i).Value), "compensation payment") > 0 And _
                    (InStr(LCase(.Range("M" & i).Value), "kh") > 0 Or _
                    InStr(LCase(.Range("M" & i).Value), "gd") > 0 Or _
                    InStr(LCase(.Range("M" & i).Value), "tb") > 0 Or _
                    InStr(LCase(.Range("M" & i).Value), "kc") > 0 Or _
                    InStr(LCase(.Range("M" & i).Value), "tg") > 0 Or _
                    InStr(LCase(.Range("M" & i).Value), "gr") > 0 Or _
                    InStr(LCase(.Range("M" & i).Value), "js") > 0 Or _
                    InStr(LCase(.Range("M" & i).Value), "sc") > 0) Then
                    
                    .Rows(i).Copy Destination:=Worksheets("Sheet2").Range("A" & .Rows.Count).End(xlUp).Offset(1)
                End If
            End If
        Next i
    End With
End Sub
 
Upvote 0

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.
Thanks - unfortunately it's not pulling anything though. It seems like it's working but, nothing is pasted into sheet 2 (the active sheet).
 
Upvote 0
That suggests nothing matches all of the criteria. Without seeing the data it is hard to be more explicit.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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