Consulting

Results 1 to 3 of 3

Thread: Solved: Look excel range?

  1. #1

    Solved: Look excel range?

    Hi Guys

    I have the following code here..part of it.

    If Range("B2").Value = Range("C2").Value Then

    How can I loop it so that it goes to the next range value? like B3 = C3 etc?

    Thanks for the help.

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    [vba] dim i as long

    for i = 2 to 3 Then' or final row you want to loop for
    If Cells(i,2).Value = Cells(i,3).Value

    'some stuff
    End If

    Next i[/vba]

  3. #3
    Quote Originally Posted by CatDaddy
    [vba] dim i as long

    for i = 2 to 3 ' or final row you want to loop for
    If Cells(i,2).Value = Cells(i,3).Value Then

    'some stuff
    End If

    Next i[/vba]
    Do you mean this?

    Thanks.

    Im not sure why but im getting a type mismatch error 13 for this..Some columns are vlookup. Does this affect it?

    [vba]
    Sub Match()
    Dim i As Integer
    Dim FirstMatch As Boolean
    Dim SecondMatch As Boolean
    For i = 2 To 3
    If Cells(i, 2).Value = Cells(i, 3).Value Then 'Cells (row,column)'B = C ' Also need to find last Record
    FirstMatch = True
    Else
    FirstMatch = False
    End If
    If Cells(i, 4).Value = Cells(i, 5).Value Then 'Cells (row,column)'D = E ' Also need to find last Record
    SecondMatch = True
    Else
    SecondMatch = False
    End If
    If FirstMatch = True And SecondMatch = True Then
    Cells(i, 1).Value = "x" 'Print in Column A String
    else
    Cells(i, 1).Value = "False" 'Print in Column A String

    End If

    Next i
    End Sub

    [/vba]
    Last edited by lienlee; 07-07-2011 at 07:28 AM.

Posting Permissions

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