Results 1 to 3 of 3

Thread: compare one cell

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    compare one cell

    how do compare cell in work sheet to another cell in another sheet in vba macro excel 2003
    thanks

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Re: compare one cell


    Sub macro1()
    Dim rng As Range
    Dim md1 As Integer


    For Each rng In Range("B2:B256")
    For Each rng1 In Range("G2:G3000")
    If (Sheets("Sheet1").Cells(rng.Row, 2).Value) = Sheets("Sheet2").Cells(rng1.Row, 7).Value Then
    MsgBox (rng)
    md1 = md1 + 1
    MsgBox md1
    End If

    Next
    Next
    End Sub[/COLOR]
    [/COLOR][/COLOR][/COLOR]

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: compare one cell

    it would be advantageous to use excel's find (and findnext) method to do this
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width