range for listbox is dynamic
result is inserted in a sheet that i use as a list
result from listbox is inserted in the sheet used to generate main sheet
here is the form and the click when we click continue after selecting a choice
using excel as a database with delete and insert is a pain! ;)
-------------- code in the form ------------------
Private Sub UserForm_Initialize()
'MsgBox ("salut")
Dim rngtmp As Range
Dim rngstr As String
Dim she As Worksheet
Set she = Worksheets("list01")
Set rngtmp = rnglist01
rngstr = she.Name & "!" & rngtmp.Address
'=== dynamic range auto growth
'plage = Worksheets("list01").Range(Cells(1, 1), Cells(12, 14)).Address
'MsgBox (plage)
'.BoundColumn = 1
'.ColumnCount = 3
'.ColumnHeads = True
'.TextColumn = True
'.RowSource = "Sheet1!A2:C" & xlLastRow("Sheet1")
'.ListStyle = fmListStyleOption
'.ListIndex = 0
listinstruments.ColumnHeads = True
listinstruments.RowSource = rngstr
End Sub
Private Sub btnContinuerSelect_Click()
'colcnt = Range("poo").Columns.Count
totcol = rnglist01.Columns.Count
'=== insert new instrument
Set shedes = ActiveWorkbook.Worksheets("list03_instruments")
lasrow = shedes.UsedRange.Rows(shedes.UsedRange.Rows.Count).Row
x = 1
'=== find last empty line
For y = 2 To lasrow
If Trim(shedes.Cells(y, x).Value) = "" Then Exit For
Next
'=== use first column to tag as NOT empty (puttting a number in it)
shedes.Cells(y, x).Value = y
'=== insert choice in all columns in the listing sheet
For xoffset = 0 To totcol - 1
shedes.Cells(y, 2 + xoffset).Value = listinstruments.Column(xoffset, listinstruments.ListIndex)
Next
Unload Me
Call genmanualdf
End Sub
No comments:
Post a Comment