C
Casey
Hi,
This routine enters selected data from a multicolumn Listbox into a
named range ("TakeOffHeaders"). The code successfully puts the correct
information in the correct cells with one exception. Instead of
selecting the first empty cell in the range it begins pasting the data
in a seemingly random column. Say the first empty column in the range
is “K” instead of starting there, it starts in column “P”. When I set a
Watch on CopyCol based on value changes, the first value is different
every time I run the routine. I need help.
Here’s the Code
Option Explicit
Private Sub cmdEnterSelection_Click()
Dim rng1 As Range
Dim rng2 As Range
Dim i As Long
Dim j As Long
Dim CopyCol As Long
Set rng1 = Sheets("Takeoff").Range("TakeOffHeaders")
Set rng2 = Sheets("Takeoff").Range("StartCell")
ActiveCell = rng2
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(0, 1).Select
Loop
CopyCol = ActiveCell.Column
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) Then
With rng1
..Cells(3, CopyCol).Value = ListBox1.List(i, 0)
..Cells(1, CopyCol).Value = ListBox1.List(i, 1)
..Cells(4, CopyCol).Value = ListBox1.List(i, 2)
..Cells(5, CopyCol).Value = ListBox1.List(i, 3)
End With
CopyCol = CopyCol + 1
End If
Next i
OptionButton2.Value = True
End Sub
This routine enters selected data from a multicolumn Listbox into a
named range ("TakeOffHeaders"). The code successfully puts the correct
information in the correct cells with one exception. Instead of
selecting the first empty cell in the range it begins pasting the data
in a seemingly random column. Say the first empty column in the range
is “K” instead of starting there, it starts in column “P”. When I set a
Watch on CopyCol based on value changes, the first value is different
every time I run the routine. I need help.
Here’s the Code
Option Explicit
Private Sub cmdEnterSelection_Click()
Dim rng1 As Range
Dim rng2 As Range
Dim i As Long
Dim j As Long
Dim CopyCol As Long
Set rng1 = Sheets("Takeoff").Range("TakeOffHeaders")
Set rng2 = Sheets("Takeoff").Range("StartCell")
ActiveCell = rng2
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(0, 1).Select
Loop
CopyCol = ActiveCell.Column
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) Then
With rng1
..Cells(3, CopyCol).Value = ListBox1.List(i, 0)
..Cells(1, CopyCol).Value = ListBox1.List(i, 1)
..Cells(4, CopyCol).Value = ListBox1.List(i, 2)
..Cells(5, CopyCol).Value = ListBox1.List(i, 3)
End With
CopyCol = CopyCol + 1
End If
Next i
OptionButton2.Value = True
End Sub