Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Run time error 424 Object required ?

Private Sub userform3OK_Click()
Dim Findit As Object, CF As Object
For Each Wks In Worksheets
Set CF = Wks.UsedRange.Cells
Set Findit = CF.Find(What:=ComboBox1.Value, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext,MatchCase:=False, SearchFormat:=False)
If Not Findit Is Nothing Then MsgBox Wks.Name
Next Wks
End Sub


Can anyone tell me where the subject line error is is the above code?

Corey....
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Run time error 424 Object required ?

Corey,

Unless you haave "Wks" defined as a global level variable, you will need to do the following:

Dim Wks as Worksheet
Set Wks = Worksheets("Sheet1") ' replace Sheet1 with your worksheet name

' When you change sheets, reset Wks to point to the new one

Set Wks = Worksheets("Sheet2") ' and so on through all your sheets.

Also instead of defining CF as object, you might want to define it specifically as a Range. I have never played with using a Find like that. I probably would have used a couple of For loops such as:

Dim iRow as Integer
Dim iCol as Integer
Dim bFound as Boolean

For iRow = 1 to ActiveSheet,UsedRange.Rows.Count
For iCol = 1 to ActiveSheet.UsedRange.Columns.Count
If Cells(iRow,iCol).Value = ComboBox1.Value Then
bFound = True
' Do other things here if you want to continue searching...
Exit For ' Leave out if search is to continue
End If
Next iCol
If iFound = True Then Exit For ' Leave out if search is to continue
DoEvents ' Keep Windows Happy

Next iRow

If iFound = True Then
MsgBox Wks.Name
' Other Stuff if Necessary
End IF

Then, if searching multiple sheets you can wrap the entire thing into another loop to go through each worksheet.
"Corey" wrote in message ...
Private Sub userform3OK_Click()
Dim Findit As Object, CF As Object
For Each Wks In Worksheets
Set CF = Wks.UsedRange.Cells
Set Findit = CF.Find(What:=ComboBox1.Value, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext,MatchCase:=False, SearchFormat:=False)
If Not Findit Is Nothing Then MsgBox Wks.Name
Next Wks
End Sub


Can anyone tell me where the subject line error is is the above code?

Corey....
  #3   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Run time error 424 Object required ?

I agree Wks s/b declared (as it is a good practice),

Dim Wks As Worksheet

however, if the OP's not using option explicit, vba will treat it as a
variant and the code will still run. If he was using option explicit, he'd
get a compile error stating "variable not defined", not a run-time error.

I would ask the OP to double check the name of the combobox. Is it actually
named combobox1 or did he change it and forget to change the code? His code
runs fine on my machine (I have to remove SearchFormat:=False as I have XL
2000). Also, I would qualify Combox1 w/the name of the form, but VBA didn't
seem to mind.





"Dove" wrote:

Corey,

Unless you haave "Wks" defined as a global level variable, you will need to do the following:

Dim Wks as Worksheet
Set Wks = Worksheets("Sheet1") ' replace Sheet1 with your worksheet name

' When you change sheets, reset Wks to point to the new one

Set Wks = Worksheets("Sheet2") ' and so on through all your sheets.

Also instead of defining CF as object, you might want to define it specifically as a Range. I have never played with using a Find like that. I probably would have used a couple of For loops such as:

Dim iRow as Integer
Dim iCol as Integer
Dim bFound as Boolean

For iRow = 1 to ActiveSheet,UsedRange.Rows.Count
For iCol = 1 to ActiveSheet.UsedRange.Columns.Count
If Cells(iRow,iCol).Value = ComboBox1.Value Then
bFound = True
' Do other things here if you want to continue searching...
Exit For ' Leave out if search is to continue
End If
Next iCol
If iFound = True Then Exit For ' Leave out if search is to continue
DoEvents ' Keep Windows Happy

Next iRow

If iFound = True Then
MsgBox Wks.Name
' Other Stuff if Necessary
End IF

Then, if searching multiple sheets you can wrap the entire thing into another loop to go through each worksheet.
"Corey" wrote in message ...
Private Sub userform3OK_Click()
Dim Findit As Object, CF As Object
For Each Wks In Worksheets
Set CF = Wks.UsedRange.Cells
Set Findit = CF.Find(What:=ComboBox1.Value, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext,MatchCase:=False, SearchFormat:=False)
If Not Findit Is Nothing Then MsgBox Wks.Name
Next Wks
End Sub


Can anyone tell me where the subject line error is is the above code?

Corey...

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Run time error 424 Object required ?

I didn't fire up Excel to test what the error message would be, but as a
habit I always use Option Explicit and avoid using variants whenever
possible.

I didn't think of the possibility of changing the combo name... Having
programmed in VB for some time I have gotten in the habit of using a
meaningful name for all UI controls and a prefix for the type of control...

Also, clicking on the debug button when the error comes up (since it is a
runtime vs compile error) should point to the exact spot in the code where
the error is/was...

David

however, if the OP's not using option explicit, vba will treat it as a
variant and the code will still run. If he was using option explicit,
he'd
get a compile error stating "variable not defined", not a run-time error.

I would ask the OP to double check the name of the combobox. Is it
actually
named combobox1 or did he change it and forget to change the code? His
code
runs fine on my machine (I have to remove SearchFormat:=False as I have XL
2000). Also, I would qualify Combox1 w/the name of the form, but VBA
didn't
seem to mind.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Time error 424 Object Required Casey[_70_] Excel Programming 8 April 12th 06 07:51 PM
Run-Time Error 424 - Object Required SpottyTash Excel Programming 3 September 9th 05 02:01 PM
Object required - run time error 424. devorivivere Excel Programming 3 April 10th 04 05:43 PM
Run-time error '424': Object required Phil Bewig Excel Programming 3 February 1st 04 08:38 PM
Dget in VBA gets Object required run-time error? John MacGregor Excel Programming 1 December 17th 03 03:44 AM


All times are GMT +1. The time now is 12:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"