Setting variable values from a existing list

marksince1984

New Member
Joined
Oct 15, 2006
Messages
3
The code below reads a column from a worksheet (could be any lenght) and uses the values to populate a listbox

Code:
Dim lrow As Long
lrow = Sheets("sheetwithlist").Range("BA65336").End(xlUp) .Row
With UserForm1
.ListBox1.RowSource = "BA2:BA" & lrow 
End With

'Hide this menu
UserForm1.Hide

'Show Next form
UserForm2.Show

Now i want to set a variable for every value in that list so i can use it later on in the package

Ie
List
List Item 1 > Variable1
List Item 2 > Variable2
List Item 3 > Variable3

etc etc

Any ideas??
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I have had a crack at doing it, it all looks good execpt when it comes to creating variables (see third last line)

Code:
'Finds last row
Dim lrow As Long
lrow = Sheets("control").Range("BA65336").End(xlUp).Row


' sets the cost centres to variables
Dim count As Integer
count = 1
While count <= lrow
Outputvar(numbered as per count) = Range("BA" & lrow + 1).Value
count = count + 1
Wend
 
Upvote 0
The code below reads a column from a worksheet (could be any lenght) and uses the values to populate a listbox

Code:
Dim lrow As Long
lrow = Sheets("sheetwithlist").Range("BA65336").End(xlUp) .Row
With UserForm1
.ListBox1.RowSource = "BA2:BA" & lrow 
End With

'Hide this menu
UserForm1.Hide

'Show Next form
UserForm2.Show

Now i want to set a variable for every value in that list so i can use it later on in the package

Ie
List
List Item 1 > Variable1
List Item 2 > Variable2
List Item 3 > Variable3

etc etc

Any ideas??

You can easily refer the value like

UserForm1.ListBox1.List(0) for 1st item
UserForm1.ListBox1.List(1) for 2nd item

and so on...

Does this help?
 
Upvote 0
SOLUTION:

To create a new sheet for each item in list and place value in cell A1 of new sheet:
Code:
Sub LoopThroughWB()
Application.ScreenUpdating = False
Dim WS As Worksheet
Dim i As Long
Dim lrow As Long
Dim Mysheet As String
lrow = Sheets("Sheet1").Range("BA65336").End(xlUp).Row
For i = 2 To lrow
   Mysheet = Cells(i, 53).Text
    On Error Resume Next
    Sheets(Mysheet).Activate
    If Err = "9" Then
       Sheets.Add after:=Worksheets(Worksheets.Count)
        ActiveSheet.Name = Mysheet
        Range("A1").Value = Mysheet
        Sheets("Sheet1").Activate
    End If
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

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