B
burl_rfc
I'm having a spot of trouble with the following code, I would like to
list all the records in column A I tried to do the following,
ListItems = SourceWB.Worksheets(1).Range(.Range("A2"), _
.Range("A65536").End(xlUp)).Value
to select all the records in column A but it doesn't work, any idea
why.
Once I've selected the record of choice from the combo box, would it be
relatively easy to look at the same row in the source workbook, but
offset 1 column (column B) and depending upon it's data do a Do Case
for further processing.
For example lets say that column A contains part numbers, the part
numbers will be populated into the combo box, once I select the part
number of choice from the combo box, I want to look at the
corresponding row but offset 1 column (column B). In column B would be
product types, now depending upon the product type I would likely do a
Do Case to run further processing.
Private Sub UserForm_Initialize()
Dim ListItems As Variant, i As Integer
Dim SourceWB As Workbook
With Me.ComboBox1
.Clear ' remove existing entries from the combobox
' turn screen updating off,
' prevent the user from seeing the source workbook being opened
Application.ScreenUpdating = False
' open the source workbook as ReadOnly
Set SourceWB = Workbooks.Open("C:\Folder Name\Source
Workbook.xls", _
False, True)
ListItems = SourceWB.Worksheets(1).Range("A1:A5").Value
' get the values you want
SourceWB.Close False ' close the source workbook without saving
changes
Set SourceWB = Nothing
ListItems = Application.WorksheetFunction.Transpose(ListItems)
' convert values to a vertical array
For i = 1 To UBound(ListItems)
.AddItem ListItems(i) ' populate the listbox
Next i
.ListIndex = -1 ' no items selected, set to 0 to select the
first item
Application.ScreenUpdating = True
End With
End Sub
Thanks
burl_rfc
list all the records in column A I tried to do the following,
ListItems = SourceWB.Worksheets(1).Range(.Range("A2"), _
.Range("A65536").End(xlUp)).Value
to select all the records in column A but it doesn't work, any idea
why.
Once I've selected the record of choice from the combo box, would it be
relatively easy to look at the same row in the source workbook, but
offset 1 column (column B) and depending upon it's data do a Do Case
for further processing.
For example lets say that column A contains part numbers, the part
numbers will be populated into the combo box, once I select the part
number of choice from the combo box, I want to look at the
corresponding row but offset 1 column (column B). In column B would be
product types, now depending upon the product type I would likely do a
Do Case to run further processing.
Private Sub UserForm_Initialize()
Dim ListItems As Variant, i As Integer
Dim SourceWB As Workbook
With Me.ComboBox1
.Clear ' remove existing entries from the combobox
' turn screen updating off,
' prevent the user from seeing the source workbook being opened
Application.ScreenUpdating = False
' open the source workbook as ReadOnly
Set SourceWB = Workbooks.Open("C:\Folder Name\Source
Workbook.xls", _
False, True)
ListItems = SourceWB.Worksheets(1).Range("A1:A5").Value
' get the values you want
SourceWB.Close False ' close the source workbook without saving
changes
Set SourceWB = Nothing
ListItems = Application.WorksheetFunction.Transpose(ListItems)
' convert values to a vertical array
For i = 1 To UBound(ListItems)
.AddItem ListItems(i) ' populate the listbox
Next i
.ListIndex = -1 ' no items selected, set to 0 to select the
first item
Application.ScreenUpdating = True
End With
End Sub
Thanks
burl_rfc