View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Get range in list from combobox value


Sub test()

For Each ws In Worksheets
ComboBox1.AddItem ws.Name
Next ws
Mysheet = ComboBox1.Text
With Sheets(Mysheet)
For Each cell In .Range("B2:B50")

ListBox1.AddItem cell
Next cell
End With
End Sub

"Axel" wrote:


I have a userform, with a combobox and two listboxes. I use this code to
get the sheets names from the workbook, to the combobox:
Private Sub UserForm_Initialize()
Dim ws As Integer
For ws = 1 To Sheets.Count
ComboBox1.AddItem Sheets(ws).Name
Next
End Sub
but I want to get range "B2:B50" in listbox1 from the sheet name, who is
selected with combobox1.
I have no ideas how to solve this, and the sheet names can be changed
from one day to another, so a case statement is no good here.
Anyone please!

*** Sent via Developersdex http://www.developersdex.com ***