+ Reply to Thread
Results 1 to 2 of 2

I need to add more columns on the Listbox

  1. #1
    Registered User
    Join Date
    MS-Off Ver
    MS office 2007

    Wink I need to add more columns on the Listbox

    I need to add more columns in the filter box, now it gives an error to populate from the database. Now it is from (0-11), i need 17 columns. Please assist.

    Dim sh As Worksheet
    Set sh = ThisWorkbook.Sheets("Data")

    Dim row_number As Long
    Dim max_id As Long
    max_id = Application.WorksheetFunction.Max(sh.Range("A:A"))

    If Me.txt_id.Value = "" Then ''' Insert
    row_number = Application.WorksheetFunction.CountA(sh.Range("A:A")) + 1
    sh.Range("A" & row_number).Value = max_id + 1
    Else '''' Update
    row_number = Application.WorksheetFunction.Match(Int(Me.txt_id.Value), sh.Range("A:A"), 0)
    End If

    sh.Range("B" & row_number).Value = Me.txt_desc.Value
    sh.Range("C" & row_number).Value = Me.cmb_Room.Value
    sh.Range("D" & row_number).Value = Me.cmb_Ltype.Value
    sh.Range("E" & row_number).Value = Me.txt_Open_Date.Value
    sh.Range("F" & row_number).Value = Me.txt_openT.Value
    sh.Range("G" & row_number).Value = Me.txt_Close_Date.Value
    sh.Range("H" & row_number).Value = Me.cmb_staff.Value
    sh.Range("I" & row_number).Value = Me.cmb_Department.Value
    sh.Range("J" & row_number).Value = Me.cmb_Status.Value
    sh.Range("K" & row_number).Value = Me.txt_Comments.Value
    sh.Range("L" & row_number).Value = Me.cmb_inforstaff.Value
    sh.Range("M" & row_number).Value = Me.txtName.Value
    sh.Range("M" & row_number).Value = Me.txtName.Value
    sh.Range("N" & row_number).Value = Me.cmb_nation.Value
    sh.Range("O" & row_number).Value = Now

    Call Reset_Form

    MsgBox "Log is Updated", vbInformation

    Call Refresh_Listbox

    End Sub

    Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

    'to populate listbox from Database sheet

    Me.txt_id.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 0)

    Me.txt_desc.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 1)
    Me.cmb_Room.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 2)
    Me.cmb_Ltype.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 3)

    Me.txt_Open_Date.Value = Format(Me.ListBox1.List(Me.ListBox1.ListIndex, 4), "D-MMM-YYYY")
    Me.txt_openT.Value = Format(Me.ListBox1.List(Me.ListBox1.ListIndex, 5), "HH:MM")
    If Me.ListBox1.List(Me.ListBox1.ListIndex, 6) <> "" Then
    Me.txt_Close_Date.Value = Format(Me.ListBox1.List(Me.ListBox1.ListIndex, 6), "D-MMM-YYYY")
    End If

    Me.cmb_staff.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 7)
    Me.cmb_Department.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 8)
    Me.cmb_Status.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 9)
    Me.txt_Comments.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 10)
    Me.cmb_inforstaff.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 11)

    End Sub

  2. #2
    Forum Expert
    Join Date
    market harborough, england
    MS-Off Ver
    Excel 2010

    Re: I need to add more columns on the Listbox

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

+ 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. [SOLVED] Filling Listbox with more than 10 columns with array made from table with hidden columns
    By hemantparmar in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-16-2019, 03:53 AM
  2. [SOLVED] Moving all columns from listbox 1 to listbox 2 and see all details of an selected item
    By alexgoaga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-05-2018, 07:09 PM
  3. Listbox Row Color, Columns Alignment, Columns Borders
    By BrianAll in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2013, 10:53 AM
  4. Transfer Data From One Userform Listbox to Another Userform Listbox with 11 columns
    By sparkoft in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-18-2013, 10:54 AM
  5. [SOLVED] Multi Select ListBox, 4 columns, use NamedRange, Columns to use in list Nonconsecutive
    By CRIMEDOG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-29-2013, 11:01 AM
  6. Listbox to Listbox, no duplicates & submitting same UserForm data for each Listbox entry.
    By jamieswift1977 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 12:18 PM
  7. Listbox with multi-columns what determines the order of the columns?
    By jwright650 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2011, 03:43 PM

Tags for this Thread


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