Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

VBA question

  • 29-08-2006 01:59PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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