StjepanJones
New Member
- Joined
- Jul 27, 2011
- Messages
- 4
Hello,
I'm an extreme beginner to VBA. I'm trying to create a Userform for this Excel Workbook I'm putting together.
I have 3 worksheets that I'm working with: PPE, Compcode, and Company Configure. PPE and Compcode will be hidden when I'm done, and I want the Userform to be available in Configure Company.
The Userform contains two ListBoxes, ListBox1 and ListBox2, and 3 Buttons, Add Company, Remove Company, and Generate Worksheet.
ListBox1 lists all of the PPE items from the PPE worksheet. The worksheet itself has 2 columns (UniqPPE and PPE). I can select the companies that I want and move them over to ListBox2.
***This is as far as I got.***
What I would like to do, once the companies are selected, is choose Generate Worksheet and have it search the Compcode worksheet (UniqPPE, PPE, ICO, Origination Addrees, NAIC, Lookup Code) for all of the items with the same UniqPPE selected on PPE, and have those items copied and pasted into the Configure Company worksheet.
This is the code I have so far:
Option Explicit
Private Sub btnMoveRight_Click()
Dim iCtr As Long
For iCtr = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(iCtr) = True Then
Me.ListBox2.AddItem Me.ListBox1.List(iCtr)
End If
Next iCtr
For iCtr = Me.ListBox1.ListCount - 1 To 0 Step -1
If Me.ListBox1.Selected(iCtr) = True Then
Me.ListBox1.RemoveItem iCtr
End If
Next iCtr
End Sub
Private Sub btnMoveLeft_Click()
Dim iCtr As Long
For iCtr = 0 To Me.ListBox2.ListCount - 1
If Me.ListBox2.Selected(iCtr) = True Then
Me.ListBox1.AddItem Me.ListBox2.List(iCtr)
End If
Next iCtr
For iCtr = Me.ListBox2.ListCount - 1 To 0 Step -1
If Me.ListBox2.Selected(iCtr) = True Then
Me.ListBox2.RemoveItem iCtr
End If
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim lb As msforms.ListBox
Dim rcArray() As Variant
Dim lrw As Long, lcol As Long
Dim rngTarget As Range
Set rngTarget = Worksheets("PPE").Range("B2:B335")
ReDim Preserve rcArray(1 To rngTarget.Rows.Count, 1 To rngTarget.Columns.Count)
With rngTarget
For lcol = 1 To .Columns.Count
For lrw = 1 To .Rows.Count
rcArray(lrw, lcol) = rngTarget.Cells(lrw, lcol)
Next lrw
Next lcol
End With
Set lb = Me.ListBox1
With lb
.ColumnCount = 1
.ColumnWidths = "100"
.List = rcArray
End With
Me.ListBox1.MultiSelect = fmMultiSelectMulti
Me.ListBox2.MultiSelect = fmMultiSelectMulti
End Sub
Private Sub btnGenerate_Click()
End Sub
**************
I'm at a loss for where to go from here.
I can send along the file I'm working with. Anyone have any ideas?
I'm an extreme beginner to VBA. I'm trying to create a Userform for this Excel Workbook I'm putting together.
I have 3 worksheets that I'm working with: PPE, Compcode, and Company Configure. PPE and Compcode will be hidden when I'm done, and I want the Userform to be available in Configure Company.
The Userform contains two ListBoxes, ListBox1 and ListBox2, and 3 Buttons, Add Company, Remove Company, and Generate Worksheet.
ListBox1 lists all of the PPE items from the PPE worksheet. The worksheet itself has 2 columns (UniqPPE and PPE). I can select the companies that I want and move them over to ListBox2.
***This is as far as I got.***
What I would like to do, once the companies are selected, is choose Generate Worksheet and have it search the Compcode worksheet (UniqPPE, PPE, ICO, Origination Addrees, NAIC, Lookup Code) for all of the items with the same UniqPPE selected on PPE, and have those items copied and pasted into the Configure Company worksheet.
This is the code I have so far:
Option Explicit
Private Sub btnMoveRight_Click()
Dim iCtr As Long
For iCtr = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(iCtr) = True Then
Me.ListBox2.AddItem Me.ListBox1.List(iCtr)
End If
Next iCtr
For iCtr = Me.ListBox1.ListCount - 1 To 0 Step -1
If Me.ListBox1.Selected(iCtr) = True Then
Me.ListBox1.RemoveItem iCtr
End If
Next iCtr
End Sub
Private Sub btnMoveLeft_Click()
Dim iCtr As Long
For iCtr = 0 To Me.ListBox2.ListCount - 1
If Me.ListBox2.Selected(iCtr) = True Then
Me.ListBox1.AddItem Me.ListBox2.List(iCtr)
End If
Next iCtr
For iCtr = Me.ListBox2.ListCount - 1 To 0 Step -1
If Me.ListBox2.Selected(iCtr) = True Then
Me.ListBox2.RemoveItem iCtr
End If
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim lb As msforms.ListBox
Dim rcArray() As Variant
Dim lrw As Long, lcol As Long
Dim rngTarget As Range
Set rngTarget = Worksheets("PPE").Range("B2:B335")
ReDim Preserve rcArray(1 To rngTarget.Rows.Count, 1 To rngTarget.Columns.Count)
With rngTarget
For lcol = 1 To .Columns.Count
For lrw = 1 To .Rows.Count
rcArray(lrw, lcol) = rngTarget.Cells(lrw, lcol)
Next lrw
Next lcol
End With
Set lb = Me.ListBox1
With lb
.ColumnCount = 1
.ColumnWidths = "100"
.List = rcArray
End With
Me.ListBox1.MultiSelect = fmMultiSelectMulti
Me.ListBox2.MultiSelect = fmMultiSelectMulti
End Sub
Private Sub btnGenerate_Click()
End Sub
**************
I'm at a loss for where to go from here.
I can send along the file I'm working with. Anyone have any ideas?