Consulting

Results 1 to 3 of 3

Thread: [Help]Export ListBox contents to new workbook via CommandButton!

  1. #1
    VBAX Newbie
    Joined
    Jul 2015
    Posts
    3
    Location

    [Help]Export ListBox contents to new workbook via CommandButton!

    On page "Tim_TKSua" , i had try code(attachment file) want to Export ListBox contents to new workbook via CommandButton1, but when i hitting commandbutton1 it will be error(image attachment).Pls help me. thanks all.
    Untitled.jpg
    Attached Files Attached Files
    Last edited by newskin; 07-22-2015 at 01:36 AM.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Your ListBox1.Rowsource property is an empty string because you assigned an array to ListBox1.List.
    Try this alternative for the same procedure where the error occurs:
    Private Sub CommandButton1_Click()
    Dim aSheet, aWind
    Dim oW
    
    Set aWind = ThisWorkbook
    Set aSheet = ActiveSheet
    Set oW = Workbooks.Add
    cvcv = ListBox1.List
    Sheet1.Range("A1:R1").Copy  ' headers
    With oW.Sheets(1).Cells(1).Resize(, 18)
      .PasteSpecial xlAll
      .PasteSpecial Paste:=xlPasteColumnWidths
      .Offset(1).Resize(UBound(cvcv) + 1, UBound(cvcv, 2) + 1) = cvcv
      Sheet1.Range("A2:R2").Copy  ' for formatting only.
      .Offset(1).Resize(UBound(cvcv) + 1).PasteSpecial Paste:=xlPasteFormats
    End With
    oW.Sheets(1).Name = Format(Now(), "yyyy-mm-dd") & " Transfer"
    Cells(1, 1).Select
    aWind.Activate
    Application.CutCopyMode = False
    aSheet.Activate
    oW.Activate
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •