Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VBA question

Options
  • 29-08-2006 1:59pm
    #1
    Registered Users Posts: 1,463 ✭✭✭


    how do you compare strings in VBA?
    i have a worksheet and i wana say loop through column A and B at the same time and compare them to columns C and D until there is a match (where the info in A is the same as C and the info in B is the same in D but their on different rows)

    i Know in C its like
    If(col A == col C) && (col B == colD)
    {
    result = match
    }
    but how do i do this in VBA?

    also when comparing strings how do you look for just part of the word
    for example i have a number 11.23 in one column and in another i have GEN 11.23 and these match based on the number.so basically i wana just compare on the numbers and not the text


Comments

  • Closed Accounts Posts: 17 Merik


    Hi

    You could use Instr to return the position of 1 string in another. If its greater than zero then it exists in that string.

    i.e.

    Dim bMatch As Boolean
    bMatch = False
    If InStr(1, "GEN 11.23", "11.23") > 0 Then
    bMatch = True
    End If

    Instr checks for the occurance of 11.23 in GEN 11.23, the actual result is 5, because it starts at the 5th position, so if its > 0 then we have a match. If you want to get more complicated comparissons you'll probably have to look into regular expressions, but I dont think these are supported in the current versions of VBA.

    Will.


  • Registered Users Posts: 1,463 ✭✭✭fifib


    thanks merik

    have another question (surprse surprise..im so crap at this)....but if i want to use information from different worksheets to do calculations and comparisons is it as simple as...for example....

    wrksheet1.cells(1,2).value + wrksheet2.Cells(2,4).value = wrksheet3.Cells(1,1).Value

    ...or is it more complicated


Advertisement