I am running Excel 2007 and writing code that will be running on other computers with Excel 2003.
I am writing my first code for a userform Combobox. I borrowed some code from one of Norie's posts and am attempting to modify for my use (code below).
The ComboBox will use a range of cells that I have copied, pasted into a separate spreadsheet and removed any duplicates. The range may change based on the version of the assembly. I am attempting to get the UserForm to populate the dropdown list and keep getting errors. Here is the code with the line in red where I am currently stuck.
Additionally, the UserForm3 code is (I have not worked through the code this far yet, so i do not know if it works or not:
Here is what I need: Look at the code and see what the errors are. Please let me know what they are and what I can do to correct them.
NOTE: My current range is from A1:A66 (although that changes). There is a header row in column so the cells that I want to appear on the dropdown list are A2:A66.
Thank you in advance for any help!
Charles
I am writing my first code for a userform Combobox. I borrowed some code from one of Norie's posts and am attempting to modify for my use (code below).
The ComboBox will use a range of cells that I have copied, pasted into a separate spreadsheet and removed any duplicates. The range may change based on the version of the assembly. I am attempting to get the UserForm to populate the dropdown list and keep getting errors. Here is the code with the line in red where I am currently stuck.
Code:
Option Explicit
Private Sub ComboBox1_Change()
Dim ws As Worksheet
Dim rng As Range
Dim i As Long
Dim ComboBox1 As ComboBox
Dim ListBox1 As ListBox
' check item has been selected
If ComboBox1.ListIndex <> -1 Then
ListBox1.Clear
Set ws = Worksheets("PartNums")
Set rng = ws.Range("A2:A66")
While rng.Value <> ""
[COLOR="Red"] ListBox1.AddItem (ws.Name)[/COLOR]
ListBox1.List(ListBox1.ListCount - 1, 1) = rng.Value
For i = 2 To 6
ListBox1.List(ListBox1.ListCount - 1, 2) = rng.Offset(, i + 5).Value
Next i
Set rng = rng.Offset(1)
Wend
' End If
End Sub
Private Sub PNs_for_ARCT00232()
Dim j As Long
Dim ce1 As String
Sheets("ARCT00232").Select
Range("D:D").Select
Selection.Copy
Sheets("PartNums").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.DisplayAlerts = False
Cells.Select
Selection.Columns.AutoFit
Columns("A:A").Select
Selection.RemoveDuplicates Columns:=1, Header:=xlYes
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
j = Application.WorksheetFunction.CountA(Selection)
Range("B1").Select
ActiveCell = j
Range("A1").Select
Application.DisplayAlerts = False
Call ComboBox1_Change
If TypeName(Selection) = "Range" Then
UserForm3.Show
End If
Range("B1").Select
End Sub
Additionally, the UserForm3 code is (I have not worked through the code this far yet, so i do not know if it works or not:
Code:
Private Sub UserForm3_Initialize()
ListBox1.ColumnCount = 6
For Each ws In Worksheets
ComboBox1.AddItem ws.Name
Next ws
End Sub
Here is what I need: Look at the code and see what the errors are. Please let me know what they are and what I can do to correct them.
NOTE: My current range is from A1:A66 (although that changes). There is a header row in column so the cells that I want to appear on the dropdown list are A2:A66.
Thank you in advance for any help!
Charles