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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
Something like this
Code:
'========================================================================================
'- WORKSHEET ERROR TRAPPING
'========================================================================================
Sub test()
    '------------------------------------------------------------------------------------
    'if A10 is less than K10 then message:"CC is missing"
    With Worksheets("Sheet4")
        If .Range("A10").Value < .Range("K10").Value Then
            MsgBox ("CC is missing (A10 < K10)")
            Application.Goto .Range("A10")
            Exit Sub
        End If
    End With
    '------------------------------------------------------------------------------------
    'If A10 in any of the sheets (array) does not match with sheet4 column A
    'then message:"CC is invalid"
    x = Worksheets("Sheet4").Range("A10").Value
    For Each s In Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4"))
        If s.Name <> "Sheet4" And s.Range("A10").Value <> x Then
            MsgBox ("CC is invalid " & vbCr _
                & s.Name & " Range A10 should = " & x)
            Application.Goto Worksheets(s.Name).Range("A10")
            Exit Sub
        End If
    Next
    '------------------------------------------------------------------------------------
    '- REST OF CODE
    MsgBox ("No Errors")
End Sub
'========================================================================================
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,388
Messages
5,511,030
Members
408,823
Latest member
TJKnight

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top