![]() |
Error if text not found
I am trying to get a Excel-macro to lookup text in a cell on one worksheet
and find the same text in another worksheet. It works fine until it reaches a text that can't be found on the other worksheet. This is my code Dim Celle As String Celle = ActiveCell Sheets("Stykliste").Select Cells.Find(What:=Celle, After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlNext).Select I get a "Run-time Error 91" What am I doing wrong? Regards Jens Nielsen |
Error if text not found
try this. Change sheet6 to your sheetname
Sub findem()'from activecell on source sheet Dim Celle As String Dim x As Range Celle = ActiveCell x = Sheets("Sheet6").Cells.Find(What:=Celle, After:=[A1], SearchOrder:=xlByRows, _ SearchDirection:=xlNext).Address Application.Goto Sheets("sheet6").Range(x) 'usually NOT necessary to select End Sub -- Don Guillett SalesAid Software "Jens Nielsen" wrote in message . dk... I am trying to get a Excel-macro to lookup text in a cell on one worksheet and find the same text in another worksheet. It works fine until it reaches a text that can't be found on the other worksheet. This is my code Dim Celle As String Celle = ActiveCell Sheets("Stykliste").Select Cells.Find(What:=Celle, After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlNext).Select I get a "Run-time Error 91" What am I doing wrong? Regards Jens Nielsen |
Error if text not found
try this instead Sub findem() Dim Celle As String Celle = ActiveCell x = Sheets("Sheet6").Cells.Find(What:=Celle, After:=[A1], SearchOrder:=xlByRows, _ SearchDirection:=xlNext).Address Application.Goto Sheets("sheet6").Range(x) End Sub -- Don Guillett SalesAid Software "Jens Nielsen" wrote in message . dk... I am trying to get a Excel-macro to lookup text in a cell on one worksheet and find the same text in another worksheet. It works fine until it reaches a text that can't be found on the other worksheet. This is my code Dim Celle As String Celle = ActiveCell Sheets("Stykliste").Select Cells.Find(What:=Celle, After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlNext).Select I get a "Run-time Error 91" What am I doing wrong? Regards Jens Nielsen |
All times are GMT +1. The time now is 05:42 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com