View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
sebastienm sebastienm is offline
external usenet poster
 
Posts: 694
Default ListBox "dynamic fill range"

Hi TK,
Are you speaking of the listbox location? ie the listbox being on a Userform
vs the listbox being on a sheet?
The properties of the listbox are not the same whether the listbox is on a
UserForm or on a Sheet.
Userform Sheet
Source Data ListFillRange RowSource
Destination LinkedCell Control Source

Regards,
Sebastien

"TK" wrote:

Hi:

The following code works as expected, but I'm trying to make the
listbox fill range dynamic with the code between
'///////////
..........
..........
'//////////

It works on form's listbox but not a sheet's listbox.


Private Sub ListBox2_Click()

Dim SourceData As Range
Dim Val1 As String
Dim Val2 As String
'////////////////////////////////////
' Dim myRng As Range

' With Worksheets("sheet4")
' Set myRng = .Range("a1:b" & .Cells(.Rows.Count, "A").End(xlUp).Row)
' End With
' ListBox2.ListFillRange = myRng.Address(external:=True)
' Set SourceRange = Range(ListBox2.ListFillRange)

'/////////////////////////////////////

'replace the following line with above
Set SourceRange = Range(ListBox2.ListFillRange)

Val1 = ListBox2.Value
Val2 = SourceRange.Offset(ListBox2.ListIndex, 1).Resize(1, 1).Value

Label1.Caption = Val1 & " " & Val2

If ActiveCell.Column = 1 Then
ActiveCell.Value = Val1
ActiveCell.Offset(0, 3) = Val2
ActiveCell.Offset(1, 0).Activate

Else
MsgBox "Put the CellPointer in the right column"
End If
End Sub

I would appreciate any help or example.


Thanks
TK