+ Reply to Thread
Results 1 to 4 of 4

Can you help me with a quick code to migrate the list box to an excel sheet?

Hybrid View

  1. #1
    Registered User
    Join Date
    10-16-2021
    Location
    egypt
    MS-Off Ver
    2016
    Posts
    75

    Can you help me with a quick code to migrate the list box to an excel sheet?

    Can you help me with a quick code to migrate the list box to an excel sheet?
    The name of the report
    range (b8:r)
    thank you for your interest

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,385

    Re: Can you help me with a quick code to migrate the list box to an excel sheet?

    Let's see if this is what you are seeking ...

    Private Sub TransferButton_Click()
     Dim lItem As Long, lRows As Long, lCols As Long
     Dim bSelected As Boolean
     Dim lColLoop As Long, lTransferRow As Long
        
     'Pass row & column count to variables
     'Less 1 as "Count" starts at zero
    lRows = ListBox1.ListCount - 1
    lCols = ListBox1.ColumnCount - 1
     
        'Ensure they have at least 1 row selected
        For lItem = 0 To lRows
            'At least 1 row selected
            If ListBox1.Selected(lItem) = True Then
                'Boolean flag
                bSelected = True
                'Exit for loop
                Exit For
            End If
        Next
         
        'At least 1 row selected
        If bSelected = True Then
            With Sheet1.Range("D1", Sheet1.Cells(lRows + 1, 4 + lCols)) 'Transfer to range CHANGE SHEET AND RANGE HERE !!!
                .Cells.Clear 'Clear transfer range
                For lItem = 0 To lRows
                    If ListBox1.Selected(lItem) = True Then 'Row selected
                      'Increment variable for row transfer range
                      lTransferRow = lTransferRow + 1
                        'Loop through columns of selected row
                        For lColLoop = 0 To lCols
                           'Transfer selected row to relevant row of transfer range
                           .Cells(lTransferRow, lColLoop + 1) = ListBox1.List(lItem, lColLoop)
                            'Uncheck selected row
                           ' ListBox1.Selected(lItem) = False
                        Next lColLoop
                    End If
                Next
            End With
            'Unload Me
        Else ' NO listbox row chosen
             MsgBox "Nothing chosen", vbCritical
        End If
    
    End Sub
    
    
    Private Sub UserForm_Initialize()
        'Set ListBox ColumnCount to the same as RowSource
        ListBox1.ColumnCount = Range(ListBox1.RowSource).Columns.Count
    End Sub
    Attached Files Attached Files

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,955

    Re: Can you help me with a quick code to migrate the list box to an excel sheet?

    Why migrate the listbox info...Surely the listbox gets it's info from a sheet...So...Just migrate the sheet...
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    10-16-2021
    Location
    egypt
    MS-Off Ver
    2016
    Posts
    75

    Re: Can you help me with a quick code to migrate the list box to an excel sheet?

    thank you v much

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Migrate MSWord Table into Excel, Keep Cell Structure
    By CaseyCayce in forum Excel General
    Replies: 0
    Last Post: 08-19-2021, 05:30 AM
  2. [SOLVED] Required vba code for save party code in group list sheet
    By sbvaram in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-08-2020, 05:04 AM
  3. Replies: 2
    Last Post: 03-03-2019, 02:50 AM
  4. How to make Macro which will Migrate info from another Excel file by Some Cryteria
    By Koko Tagauri in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2013, 09:50 AM
  5. [SOLVED] List of Codes on one sheet, Billing data on another sheet, highlight code if in list
    By children in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-18-2013, 05:03 PM
  6. How to migrate from an Excel file to another
    By nacersaleh in forum Excel General
    Replies: 1
    Last Post: 07-15-2013, 10:22 AM
  7. Migrate multi line data from one sheet to another
    By softspoke in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-27-2008, 05:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1