• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Match with conditions help!

Ella63112

New Member
So I have a single cell reference and I am trying to search another sheet to find the first match in column c and add 1 to the value in column m. However if column m matches the value in column p, I want to find the next match and add one with the same conditions. If I find a match and add 1 to the value in column m, I want the macro to stop. If all matches produce a matched value between column p and m, I want to still add one to the first match.


Can someone help. I currently have something created that finds the first match and adds one to the value in column M, but I am stuck on how to proceed.
 
 
So I have a single cell reference and I am trying to search another sheet to find the first match in column c and add 1 to the value in column m. However if column m matches the value in column p, I want to find the next match and add one with the same conditions. If I find a match and add 1 to the value in column m, I want the macro to stop. If all matches produce a matched value between column p and m, I want to still add one to the first match.


Can someone help. I currently have something created that finds the first match and adds one to the value in column M, but I am stuck on how to proceed.
This is a sample of what I have so far:

>>> use code - tags <<<
Code:
Sub CountEachScan()
Dim RangeToMatch As Excel.Range
Dim cell As Excel.Range
Dim C1Value As Variant
Dim C1Row As Variant

Set RangeToMatch = Sheets("Sheet1").Range("A:A")
For Each cell In RangeToMatch
    C1Value = cell.Value
    With Sheets("SHIPPED")
        C1Row = Application.Match(C1Value, .Range("B:B"), 0)
        If Not IsError(C1Row) Then
            If Not .Range("M" & C1Row).Value > .Range("I" & C1Row).Value Then
            .Range("M" & C1Row).Value = .Range("M" & C1Row).Value + 1
           If Not .Range("M" & C1Row).Value + .Range("I" & C1Row).Value Then
           Resume Next
            .Range("M" & C1Row).Value = .Range("M" & C1Row).Value + 1
           
        End If
    End With
Next
End Sub
 
Last edited by a moderator:
This is a sample of what I have so far:

>>> use code - tags <<<
Code:
Sub CountEachScan()
Dim RangeToMatch As Excel.Range
Dim cell As Excel.Range
Dim C1Value As Variant
Dim C1Row As Variant

Set RangeToMatch = Sheets("Sheet1").Range("A:A")
For Each cell In RangeToMatch
    C1Value = cell.Value
    With Sheets("SHIPPED")
        C1Row = Application.Match(C1Value, .Range("B:B"), 0)
        If Not IsError(C1Row) Then
            If Not .Range("M" & C1Row).Value > .Range("I" & C1Row).Value Then
            .Range("M" & C1Row).Value = .Range("M" & C1Row).Value + 1
           If Not .Range("M" & C1Row).Value + .Range("I" & C1Row).Value Then
           Resume Next
            .Range("M" & C1Row).Value = .Range("M" & C1Row).Value + 1
          
        End If
    End With
Next
End Sub
So at the very least does anyone know the best command to use matching my reference?
 
According to post #2 link the attachment is still missing !​
A before state and an exact expected result state may help to decypher your explanation, as coding can't be guessing …​
 
Attached is a sample workbook. All I'm looking to do is add 1 to Column m if the referenced number on sheet two matches the number in Column B. I only want to add 1 a single time. However, if the number in Column m matches the number in the shipped column I want to continue searching for a match and add one elsewhere. If all findings on the sheet have the same number in in the shipped Column and Column M, I want it to add one to the first match. Attached is a sample workbook.
 

Attachments

  • Book5.xlsx
    17.2 KB · Views: 5
Back
Top