LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Must be better way...Using Listbox Selection to Query Data

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox & Selection sparx Excel Discussion (Misc queries) 0 July 31st 06 10:48 PM
Using a ListBox selection to query a database CLamar Excel Discussion (Misc queries) 1 June 1st 06 07:32 PM
ListBox selection GMet Excel Programming 1 September 24th 04 08:02 PM
data selection query no1. SS[_2_] Excel Programming 5 December 4th 03 08:11 PM
data selection query no2 SS[_2_] Excel Programming 2 December 4th 03 07:27 PM


All times are GMT +1. The time now is 01:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"