messages for conditions;If/and/or

bgonen

Active Member
Joined
Oct 24, 2009
Messages
264
I am trying to add a procedure before the one below that will compare cell/s A10, A11, A12 etc with K10,K11,K12 respectively
For example; if A10 is less than K10 then message:"CC is missing"
If A10 in any of the sheets (array) does not match with sheet4 column A then message:"CC is invalid"
Only after that the procedure in blue (below) can be executed.

Sub MatchCopyPaste2()
Dim LR As Long, i As Long, ws As Worksheet
Application.ScreenUpdating = False
Sheets("DataByCC").UsedRange.Offset(1).ClearContents
For Each ws In Sheets(Array("P_ROLL", "Travel"))
With ws
LR = .Range("A" & Rows.Count).End(xlUp).Row
For i = 10 To LR
With .Range("A" & i)
If IsNumeric(Application.Match(.Value, .Columns("A"), 0)) Then
.EntireRow.SpecialCells(12).Copy Destination:=Sheets("DataByCC").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
End With
Next i
End With
Next ws
End Sub
 

Some videos you may like

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I think maybe you clicked the wrong button, that is not blue, it is gigantic text.
Here it is again at a normal size:

Code:
Sub MatchCopyPaste2()
Dim LR As Long, i As Long, ws As Worksheet
Application.ScreenUpdating = False
Sheets("DataByCC").UsedRange.Offset(1).ClearContents
For Each ws In Sheets(Array("P_ROLL", "Travel"))
With ws
LR = .Range("A" & Rows.Count).End(xlUp).Row
For i = 10 To LR
With .Range("A" & i)
If IsNumeric(Application.Match(.Value, .Columns("A"), 0)) Then
.EntireRow.SpecialCells(12).Copy Destination:=Sheets("DataByCC").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
End With
Next i
End With
Next ws
End Sub

Also, why are you using Application.Match instead of the VBA Find method?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,313
Members
414,052
Latest member
Dual Showman

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
Top