Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Modify Claus code "Sub Array_Var_Column_Sort()"

This seems to work but I don't trust my judgment on evaluating the outcome.

Trying to apply the row count of each variable length column to the specific column to sort.

Lrow1, 2, 3 show correct row numbers in varRow = Array(LRow1, LRow2, LRow3)

Using A1, C1 & E1 pulled down to various row lengths for testing.

I have gotten a 6 row gap in the sort in column A once in awhile.

Thanks.
Howard


Sub Array_Var_Column_Sort()

Dim LRow1 As Long, LRow2 As Long, LRow3 As Long
Dim LRowX As Long, LCol As Long
Dim i As Long, ii As Long
Dim varKey As Variant
Dim varRow As Variant

Application.ScreenUpdating = False

With Sheets("sheet5")
'Last rows
LRow1 = .Cells(Rows.Count, 1).End(xlUp).Row
LRow2 = .Cells(Rows.Count, 3).End(xlUp).Row
LRow3 = .Cells(Rows.Count, 5).End(xlUp).Row

'Last column
'LCol = .Cells(1, Columns.Count).End(xlLeft).Column
LCol = Cells.Find(What:="*", After:=[a1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column

'Sortkeys
varKey = Array("A1", "C1", "E1")
varRow = Array(LRow1, LRow2, LRow3)

.Sort.SortFields.Clear
For i = LBound(varKey) To UBound(varKey)
For ii = LBound(varRow) To UBound(varRow)

.Range(.Cells(1, 1), .Cells(varRow(ii), LCol)).Sort _
Key1:=.Range(varKey(i)), order1:=xlAscending, Header:=xlNo 'Header:=xlYes

Next
Next
End With
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Modify Claus code "Sub Array_Var_Column_Sort()"

LCol = Cells.Find(What:="*", After:=[a1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column


Curious why you used this instead of...

lLastCol = Cells(1, Columns.Count).End(xlToLeft).Column

...as you have in the line above (which contains the wrong direction
constant)! This makes for better self-documenting, consistency, and
code brevity!

Otherwise, I don't see in your code why you occasionally get gaps in
colA. Perhaps a runtime issue? Hard to say without knowing the actual
data you're trying to sort. What's the runtime ratio for it to occur?
You can send me the file if you want to see if it happens for me...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Modify Claus code "Sub Array_Var_Column_Sort()"

On Thursday, August 21, 2014 6:27:13 PM UTC-7, GS wrote:
LCol = Cells.Find(What:="*", After:=[a1], _


SearchOrder:=xlByColumns, _


SearchDirection:=xlPrevious).Column




Curious why you used this instead of...



lLastCol = Cells(1, Columns.Count).End(xlToLeft).Column



..as you have in the line above (which contains the wrong direction

constant)! This makes for better self-documenting, consistency, and

code brevity!



Otherwise, I don't see in your code why you occasionally get gaps in

colA. Perhaps a runtime issue? Hard to say without knowing the actual

data you're trying to sort. What's the runtime ratio for it to occur?

You can send me the file if you want to see if it happens for me...



--

Garry



Hi Garry,

lLastCol = Cells(1, Columns.Count).End(xlToLeft).Column


This returns 16384, did not seem to right with only three columns A, C & D on my test sheet. I wondered if Claus was setting the sheet to do any number of columns, but don't know.

As far as the sheet I'm testing on it is a blank new sheet and in column A "a1" and pull down 20-30 rows, same with C and D columns. I then mix the data and run the code. So the sheet is real plain jane.

The gap in col A is not consistent, strange and it could have been something I did and was not aware of. Sorta the reason I posted here to get a critical review of the mods I made.

I have no project for this, just occurred to me to try it since not all columns may be the exact same number of rows.

Claus' code took the column length from a single column and applied it to all.

So low priority for sure.

Howard

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Modify Claus code "Sub Array_Var_Column_Sort()"

On Thursday, August 21, 2014 6:27:13 PM UTC-7, GS wrote:
LCol = Cells.Find(What:="*", After:=[a1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column




Curious why you used this instead of...



lLastCol = Cells(1, Columns.Count).End(xlToLeft).Column



..as you have in the line above (which contains the wrong direction

constant)! This makes for better self-documenting, consistency, and

code brevity!



Otherwise, I don't see in your code why you occasionally get gaps in

colA. Perhaps a runtime issue? Hard to say without knowing the
actual

data you're trying to sort. What's the runtime ratio for it to
occur?

You can send me the file if you want to see if it happens for me...



--

Garry



Hi Garry,

lLastCol = Cells(1, Columns.Count).End(xlToLeft).Column


This returns 16384, did not seem to right with only three columns A,
C & D on my test sheet. I wondered if Claus was setting the sheet to
do any number of columns, but don't know.

As far as the sheet I'm testing on it is a blank new sheet and in
column A "a1" and pull down 20-30 rows, same with C and D columns. I
then mix the data and run the code. So the sheet is real plain jane.

The gap in col A is not consistent, strange and it could have been
something I did and was not aware of. Sorta the reason I posted here
to get a critical review of the mods I made.

I have no project for this, just occurred to me to try it since not
all columns may be the exact same number of rows.

Claus' code took the column length from a single column and applied
it to all.

So low priority for sure.

Howard


Ok! The file you're playing with IS a project and so if you send it to
me I'll play too!<g

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Modify Claus code "Sub Array_Var_Column_Sort()"

On Thursday, August 21, 2014 7:34:01 PM UTC-7, GS wrote:
On Thursday, August 21, 2014 6:27:13 PM UTC-7, GS wrote:


LCol = Cells.Find(What:="*", After:=[a1], _


SearchOrder:=xlByColumns, _


SearchDirection:=xlPrevious).Column








Curious why you used this instead of...








lLastCol = Cells(1, Columns.Count).End(xlToLeft).Column








..as you have in the line above (which contains the wrong direction




constant)! This makes for better self-documenting, consistency, and




code brevity!








Otherwise, I don't see in your code why you occasionally get gaps in




colA. Perhaps a runtime issue? Hard to say without knowing the


actual




data you're trying to sort. What's the runtime ratio for it to


occur?




You can send me the file if you want to see if it happens for me...








--




Garry






Hi Garry,




lLastCol = Cells(1, Columns.Count).End(xlToLeft).Column




This returns 16384, did not seem to right with only three columns A,


C & D on my test sheet. I wondered if Claus was setting the sheet to


do any number of columns, but don't know.




As far as the sheet I'm testing on it is a blank new sheet and in


column A "a1" and pull down 20-30 rows, same with C and D columns. I


then mix the data and run the code. So the sheet is real plain jane.




The gap in col A is not consistent, strange and it could have been


something I did and was not aware of. Sorta the reason I posted here


to get a critical review of the mods I made.




I have no project for this, just occurred to me to try it since not


all columns may be the exact same number of rows.




Claus' code took the column length from a single column and applied


it to all.




So low priority for sure.




Howard




Ok! The file you're playing with IS a project and so if you send it to

me I'll play too!<g



--

Garry



And after more testing the gap is now consistent but is in column C.

Data drops about 8 rows and the text to the right also is moved down several rows.

This is now in the weird category!

https://www.dropbox.com/s/y1sx72rxgs...rop%20Box.xlsm

Howard


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Modify Claus code "Sub Array_Var_Column_Sort()"


Garry,

Try this one, I think I sent wrong link in last post

https://www.dropbox.com/s/ep41xcpsw5...20Box%20X.xlsm

Howard
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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
How Do I Modify Pearson's Code to Add "Treat Consecutive Delimiters As One"? [email protected] Excel Programming 4 June 14th 06 12:23 AM
Can you "duplicate" "copy" listboxes and code to multiple cells? HotRod Excel Programming 1 September 1st 04 05:03 PM
Modify code to disable "paste" Jonsson[_34_] Excel Programming 0 June 17th 04 09:10 AM
Looking for VB code to test for "RING" , "BUSY" disconnects or other signals BruceJ[_2_] Excel Programming 3 November 20th 03 01:55 AM


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

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"