+ Reply to Thread
Results 1 to 3 of 3

Search ListBox, Move Data and Delete Source Data

  1. #1
    Registered User
    Join Date
    06-13-2018
    Location
    England
    MS-Off Ver
    2013
    Posts
    9

    Search ListBox, Move Data and Delete Source Data

    Hi All,

    I am working on a user form using a ListBox called ListBox1 and TextBox called TextBox10 and a command button called cmdArchove

    ListBox1 contains 11 columns of data which is sourced from sheet1 A2:K

    The idea is to use TextBox10 to search ListBox1, then use multiselect to chose employee items to archive in sheet4 and deleting from source on sheet1.

    The data in column 11 is a unique reference number for each row of data.

    Can anyone help with a code to enable this to happen?

    Many thanks in advance.

    Andy

  2. #2
    Registered User
    Join Date
    06-13-2018
    Location
    England
    MS-Off Ver
    2013
    Posts
    9

    Re: Search ListBox, Move Data and Delete Source Data

    This is the code I currently have but if I search the list and chose the records to archive it copies the data to sheet4 but deletes data from the top of sheet1 even if the data copied is from further down the sheet.

    Please Login or Register  to view this content.
    Private Sub TextBox10_Change()
    Dim J As Long
    Dim testString As String


    testString = LCase("*" & TextBox10.text & "*")


    With ListBox1
    For J = .ListCount - 1 To 0 Step -1
    If (Not (LCase(.List(J, 0)) Like testString) And (Not (LCase(.List(J, 1)) Like testString))) _
    And (Not (LCase(.List(J, 2)) Like testString) And (Not (LCase(.List(J, 3)) Like testString))) Then
    .RemoveItem J
    End If
    Next J
    End With
    End Sub


    Private Sub UserForm_Initialize()
    With Sheet1
    ListBox1.ColumnCount = 11
    ListBox1.List = Sheets("HERS Data").Range("A2:K" & Sheets("HERS Data").Cells(Rows.Count, 1).End(xlUp).Row).value

    End With

    End Sub

    Private Sub cmdArchive_Click()
    Dim lRw As Long
    Dim iX As Integer, iY As Integer
    Dim indexi As Long
    For iX = 0 To ListBox1.ListCount - 1
    If Me.ListBox1.Selected(iX) = True Then
    With Sheet4
    lRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
    For iY = 0 To Me.ListBox1.ColumnCount - 1
    .Cells(lRw, iY + 1).value = Me.ListBox1.List(iX, iY)


    Next iY
    End With

    End If





    Next iX


    Dim I As Long





    With ListBox1
    For I = .ListCount - 1 To 0 Step -1
    If .Selected(I) Then
    .RemoveItem I
    Sheets("HERS Data").Rows(I + 2).EntireRow.Delete

    End If
    Next I

    End With

    Unload Me
    ArchiveOperative.Show

    End Sub
    Please Login or Register  to view this content.
    Many Thanks

    Andy
    Last edited by Andyw111; 06-27-2018 at 03:33 AM.

  3. #3
    Registered User
    Join Date
    06-13-2018
    Location
    England
    MS-Off Ver
    2013
    Posts
    9

    Re: Search ListBox, Move Data and Delete Source Data

    Duplicate post deleted
    Last edited by Andyw111; 06-27-2018 at 03:32 AM. Reason: Duplicate post deleted

+ 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] Delete item from listbox and row source/named range
    By syedmehdi in forum Excel General
    Replies: 14
    Last Post: 11-12-2019, 06:55 PM
  2. Search Data Through Listbox Userform and Fill Specific data Text Boxes in other form
    By mahmudayaz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-10-2017, 09:25 AM
  3. [SOLVED] Listbox to source two sets of data
    By yachrishere in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2016, 04:20 PM
  4. [SOLVED] Listbox selection back to data source
    By evertjvr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2015, 04:45 PM
  5. Help with Userform Data Source for Listbox refrerencing using full path
    By AuntyJean in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2014, 12:57 PM
  6. Delete row source from selected line in ListBox
    By PinkMafia14 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-12-2013, 03:15 PM
  7. I need help. Huge data source, I need to clean it up. Find and move data macro.
    By sangreal2007 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 02:26 PM

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