Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Dump ListBox Contents to Sheet & Stay on Active Sheet

I am sorting a multi-column listbox using pretty much a manual method, but I finally got it to work, so I'm sticking with it. The listbox was not created from a row source, so to sort it, I basically create a temporary sheet, dump the list box contents, sort the data, copy it back to the listbox and then delete the temporary sheet. My only problem (besides speed) is that when I add the sheet and dump the contents of the listbox, I see the sheet updating as the contents are dumped. I have screenupdating off, but I still see the sheet. How can I stay on the active sheet and not watch the sheet being updated? Here's the code. Any help would be greatly appreciated!

Private Sub SortListBox(SortColumn As String)
Dim i, j, TempRow, TempCol As Integer
Dim SortField As String

ScreenUpdating = False
Sheets.Add.Name = "TempSheet"
For i = 1 To frmFindResource.ListBox1.ListCount
For j = 1 To 6
ActiveWorkbook.Sheets("TempSheet").Cells(i, j) = frmFindResource.ListBox1.List(i - 1, j - 1)
End If
Next j
Next i
TempRow = Sheets("TempSheet").UsedRange.Rows.Count
TempCol = Sheets("TempSheet").UsedRange.Columns.Count

SortField = SortColumn + CStr(TempRow)
ActiveWorkbook.Worksheets("TempSheet").Sort.SortFi elds.Clear
ActiveWorkbook.Worksheets("TempSheet").Sort.SortFi elds.Add Key:=Range( _
SortField), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("TempSheet").Sort
.SetRange Range(Cells(1, 1), Cells(TempRow, TempCol))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

For i = 1 To TempRow
For j = 1 To TempCol
frmFindResource.ListBox1.List(i - 1, j - 1) = CStr(Sheets("TempSheet").Cells(i, j))
Next j
Next i

Application.DisplayAlerts = False
Sheets("TempSheet").Delete
Application.DisplayAlerts = True
ScreenUpdating = True

End Sub
Reply
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
Prompt for file name and paste contents of active sheet Jim G Excel Programming 6 October 19th 07 04:41 AM
ListBox RowSource set to range of in-active sheet - possible? What-A-Tool Excel Programming 1 December 3rd 06 12:09 AM
Userform Listbox using an active sheet [email protected] Excel Discussion (Misc queries) 0 March 1st 06 08:22 PM
Rename active sheet to contents of specific cell burl_rfc Excel Programming 3 February 28th 06 11:34 PM
Copy from active sheet and paste into new sheet using info from cell in active Ingve Excel Programming 3 January 23rd 06 09:57 PM


All times are GMT +1. The time now is 01:09 AM.

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

About Us

"It's about Microsoft Excel"