Consulting

Results 1 to 4 of 4

Thread: If this do that, If not Do the other

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    If this do that, If not Do the other

    Thank you all for your help. I got both of those macros working in my file. However, now I need to write code to Find "CRN", if it finds it I need it to run some code but if it doesn't find it I need it to run other code. Again, I know what column it is in but not the row.

    Thank you,
    Daniel

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I have no idea to what you are referring. Can you put it in context?

  3. #3
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Gladly, I am looking to find the word "Customer" in Column A if it finds it I need it to open a file and do a vlookup from that file. If it can't find it, skip that code and go to the rest of the macro.

    Daniel

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Daniel,
    Here's a sample
    [VBA]
    Sub FindLookup()
    Dim ThsBook As Workbook, c As Range
    Application.ScreenUpdating = False
    Set ThsBook = ActiveWorkbook
    Set c = Columns(1).Find(What:="Customer")
    If Not c Is Nothing Then
    Workbooks.Open "C:\AAA\VBA.xls"
    ThsBook.Activate
    c.Offset(, 2).FormulaR1C1 = "=VLOOKUP(RC[-2],[VBA.xls]Sheet1!C2:C5,4,FALSE)"
    Exit Sub
    End If
    MsgBox "Customer not found"
    Application.ScreenUpdating = True
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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