ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problems, doing a find in another sheet. (https://www.excelbanter.com/excel-programming/314875-problems-doing-find-another-sheet.html)

Jan Kronsell[_3_]

Problems, doing a find in another sheet.
 
I have a commandbutton in a sheet, with the following code

Private Sub CommandButton1_Click()
Dim nv As String

nv = Range("a2").Value
Sheets("data").Select

Cells.Find(What:=nv, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate


End Sub

When I use the code I get a runtime error 1004: The method Activeate for the
class Range did not succeed (its in Danish so im not sure of the
translation), and it is the Cells.Find that fails.

If I do the find in the same sheet as the button, it works allright. How can
I get it to perform a seach in another sheet than contains the command
button.

Jan



Jan Kronsell[_3_]

Problems, doing a find in another sheet.
 
Additionally:

If I change my code to only contain

Sheets("data").Range("a1").Activate

I get the same error, so it seems my problem is how to activate a cell in
one sheet, from code on a button in another.

Jan





Jan Kronsell[_3_]

Problem solved !
 
I discovered that even if Ii selected sheet first I had to refer to the
sheet in the Range statement as well.

Jan



money

Problems, doing a find in another sheet.
 
Try this out.

Private Sub CommandButton1_Click()
Dim nv As String

nv = Range("a2").Value
Sheets("data").Select

Cells.Find(What:=nv, After:=ActiveCell,
LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False) _
.Activate
End Sub


-----Original Message-----
I have a commandbutton in a sheet, with the following code

Private Sub CommandButton1_Click()
Dim nv As String

nv = Range("a2").Value
Sheets("data").Select

Cells.Find(What:=nv, After:=ActiveCell,

LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows,

SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate


End Sub

When I use the code I get a runtime error 1004: The

method Activeate for the
class Range did not succeed (its in Danish so im not

sure of the
translation), and it is the Cells.Find that fails.

If I do the find in the same sheet as the button, it

works allright. How can
I get it to perform a seach in another sheet than

contains the command
button.

Jan


.



All times are GMT +1. The time now is 10:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com