Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This is the scenerio:
A small example of what I am having problems with. Data ==== A B C D Company Name State City Zip 1 Yellow Co. NY New York 10111 2 Blue Inc CT Greenwich 06830 3 Green LLC GA Atlanta 78654 4 Gold Corp. WA Seattle 90768 I set up a multi page userform with 2 list boxes on each page. List box 1 has all the companies available to analyze. User selects companies to analyze which then gets transferred to List box2. I repeat this for the other various data. ie. Listbox3 (States available) -- Listbox4(States Selected) Listbox5(Cities Avaialble) -- Listbox6(Cities Selected) Listbox7(ZipCodes Available) -- Listbox8(ZipCodes Selected) I then use the results of List box 2, 4, 6, and 8 to remove rows from the spreadsheet which do not fit into the selected query. Set LBox2 = ListBox2 Set LBox4 = ListBox4 Set LBox6 = ListBox6 Set LBox8 = ListBox8 CompanyCol = "A" myList2Company = LBox2.List myList4States=LBox4.List myList6City=LBox6.List MyList8Zip=LBox8.List Dim DelCompRow(65000) As String Dim CheckAgainComp(65000) As String Dim LastRow As Long, r As Long LastRow = ActiveSheet.UsedRange.Rows.Count LastRow = LastRow + ActiveSheet.UsedRange.Row - 1 For r = 2 To LastRow For Each Item In myList2Company If Range(CompanyCol & r).Value < Item And DelCompRow(r) < "NO" And CheckAgainComp(r) < "NO" Then DelCompRow(r) = "YES" CheckAgainComp(r) = "NO" Else If Range(CompanyCol & r).Value = Item Then DelCompRow(r) = "NO" CheckAgainComp(r) = "YES" End If End If Next Item Next r For r = 2 To LastRow If DelCompRow(r) = "YES" Then Rows(r).Clear End If Next r DeleteEmptyRows I then repeat the above code for the other column heading ie. States, Zip... My Question Is: Is there a better way to write the above code? The problem with the above is that say the user selects 20 states, it has to go through each row 20 times and then deletes it. I have to repeat the same for all the other selected items in the listbox. With 4 listboxes, multiple items per listbox, and 50,000 rows of data in my spreadsheet, this takes an extremely long time to complete and sometimes crashes. Any ideas on how this can be improved? Any help would be greatly appreciated! Thank you. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Listbox & Selection | Excel Discussion (Misc queries) | |||
Using a ListBox selection to query a database | Excel Discussion (Misc queries) | |||
ListBox selection | Excel Programming | |||
data selection query no1. | Excel Programming | |||
data selection query no2 | Excel Programming |