Transfer data from userform listbox to sheet in worksheet

jdcar

Board Regular
Joined
Apr 27, 2012
Messages
163
hi everyone
I try through net to know how to transfer data from listbox, in userform, to worksheet, but unfortunately without result.
I have, as a sample, a combobox (cbo1) that chooses the information to be shown in the listbox (lstPed), and with a commandbox (cmdPrin), which I pretend save in to worksheet, (Sheet6). In this sheet has headers that occupy three columns and two rows (A1:C2).
I woud like it to be possible with (Cmdprin), transfer the respective data for that sheet in A3:C20 cells in Sheet3. How can I do That?
Thank you
The code that I tried was the bellow:
It works BUT this code works with its immediate filling, but it continues to think or continues to go through the spreadsheet, for some time (+ - one minute), without let to passe to next operation.
Will be there a simpler way to do this? thank you for your help
Jdcar
VBA Code:
Private Sub cmdPrin_Click()
Sheets("sheet6").Select
If lstPed.ListCount = 0 Then
    MsgBox ("Não há Itens a serem impressos..."), vbInformation, ("erro")
        Else
        If Range("A3").Select = "" Then
        ' do anything
     Else
        'clean
         Range("A3").Select
         Range(Selection, Selection.End(xlToRight)).Select
         Range(Selection, Selection.End(xlDown)).Select
         Selection.ClearContents
         Range("A3").Select
        End If
‘ roll the data into the spreadsheet
 Dim Item As Double
 Dim linha As Integer
linha = 3
 For Item = 0 To lstPed.ListCount - 1
     Sheets("sheet6").Cells(linha, 1) = lstPed.List(Item, 0)
     Sheets("sheet6").Cells(linha, 2) = lstPed.List(Item, 1)
     Sheets("sheet6").Cells(linha, 3) = lstPed.List(Item, 2)
    linha = linha + 1
 Next
 End If

End sub
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Watch MrExcel Video

Forum statistics

Threads
1,126,897
Messages
5,621,499
Members
415,845
Latest member
marej123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top