PDA

View Full Version : If this do that, If not Do the other



Djblois
06-12-2006, 10:37 AM
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

Bob Phillips
06-12-2006, 10:57 AM
I have no idea to what you are referring. Can you put it in context?

Djblois
06-12-2006, 11:50 AM
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

mdmackillop
06-13-2006, 11:35 AM
Hi Daniel,
Here's a sample

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