About ComboBox ; Sheet.Name and commands

backup69

Active Member
Joined
Jan 20, 2004
Messages
271
Hi

I try make UserForm and need help
1)
I have 2 combobox in form and 1command buton.
in combobox1 i put list of items in active sheet selected range.
But i need put list of worksheets in combobox2
i have 1 code but cant finish this
Code:
For r = 1 To Worksheets.Count
'how i can put this answer directly in combo not in some sheet??
Worksheets("Sheet1").Cells(r, 1).Value = Worksheets(r).Name
Next

2)
then how i can put this 2 answer together in this code
Code:
Private Sub CommandButton1_Click()
With ActiveSheet.Range("A1:L500")'<----- in place of Activesheet need be value of combobox2( Sheet choice)
Set c = .Find(what:="here")'<------- in place "here" i need put value of combobox1( find same value and activate )
If Not c Is Nothing Then
c.Activate
Else
MsgBox "Not in this sheet"
End If
End With
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
This will add each worksheet name in a workbook to the combobox.

Dim ws as worksheet
For Each ws in activeworkbook.worksheets
Combobox1.additem ws.name
Next

To reference the combobox selected values.
Selection1 as string, selection2 as string

Selection1 = Combox1.value
Selection2 = combox2.value

Hope this helps.
 
Upvote 0
first code working for me TY, but second... i think i do something wrong?

Code:
Private Sub CommandButton1_Click()
Dim leid As String, ws As String
leid = ComboBox1.Value
ws = ComboBox2.Value

'error: invalid qualifier, ws
With ws.Range("A1:L500") 
Set new = .Find(what:="leid")
If Not new Is Nothing Then
new.Activate
Else
MsgBox "Not in this sheet"
End If
End With

End Sub
 
Upvote 0
backup69 said:
first code working for me TY, but second... i think i do something wrong?

Code:
Private Sub CommandButton1_Click()
Dim leid As String, ws As String
leid = ComboBox1.Value
ws = ComboBox2.Value

'error: invalid qualifier, ws
With ws.Range("A1:L500") 
Set new = .Find(what:="leid")
If Not new Is Nothing Then
new.Activate
Else
MsgBox "Not in this sheet"
End If
End With

End Sub

Dim leid As String, ws As String

Should be leid as string, ws as worksheet

Also

ws = ComboBox2.Value
Should be
Set Ws = Worksheet(combobo2.value)
 
Upvote 0
ohh sry but another place now :)

.Find(what:="leid")
not this way
.Find(what:=leid)
not this way
.Find(what:=(leid))
and not this way
 
Upvote 0
i found some solution

Dim leid As String, ws As Worksheet
leid = ComboBox1.Text '<-------- only this way vorks, whay i dont cnow :)
Set ws = Worksheets(ComboBox2.Value)


With ws.Range("A1:L500")
Set uus = .Find(what:=leid)
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,577
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top