Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default i would like a code for autosort left to rigth

i would like a code for autosort left to rigth
eg 1-3-5-7-3-8-4- "- represents blank cell"
1-3-3-4-5-7-8- leaving blank where they are
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default i would like a code for autosort left to rigth

Dear Anthony

Try the below code and feedback which works on Row 1.


Sub SortWOBlanks()
Dim lngCol As Long
Dim lngCount As Long
Dim lngLastCol As Long
Dim varTemp As Variant
Dim arrTemp As Variant

Application.ScreenUpdating = False
lngLastCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
varTemp = Range("A1", Cells(1, lngLastCol))
Range("A1", Cells(1, lngLastCol)).Sort Key1:=Range("A1")
lngCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
arrTemp = Range("A1", Cells(1, lngCol))
Range("A1", Cells(1, lngLastCol)) = varTemp
For lngCol = 1 To lngLastCol
If Cells(1, lngCol) < "" Then
lngCount = lngCount + 1
Cells(1, lngCol) = arrTemp(1, lngCount)
End If
Next
Application.ScreenUpdating = True

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Anthony" wrote:

i would like a code for autosort left to rigth
eg 1-3-5-7-3-8-4- "- represents blank cell"
1-3-3-4-5-7-8- leaving blank where they are

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default i would like a code for autosort left to rigth

Oops. I missed to mention the sort order.. Modified the code so as to call
from code by passing the row to be sorted... such as SortWOBlanks 1 will sort
the first row.

Sub SortWOBlanks(lngRow As Long)
Dim lngCol As Long
Dim lngCount As Long
Dim lngLastCol As Long
Dim varTemp As Variant
Dim arrTemp As Variant

Application.ScreenUpdating = False
lngLastCol = Cells(lngRow, Columns.Count).End(xlToLeft).Column
varTemp = Range(Cells(lngRow, 1), Cells(lngRow, lngLastCol))
Range(Cells(lngRow, 1), Cells(lngRow, lngLastCol)).Sort _
Key1:=Range("A" & lngRow), Orientation:=xlLeftToRight
lngCol = ActiveSheet.Cells(lngRow, Columns.Count).End(xlToLeft).Column
arrTemp = Range(Cells(lngRow, 1), Cells(lngRow, lngCol))
Range(Cells(lngRow, 1), Cells(lngRow, lngLastCol)) = varTemp
For lngCol = 1 To lngLastCol
If Cells(lngRow, lngCol) < "" Then
lngCount = lngCount + 1
Cells(lngRow, lngCol) = arrTemp(1, lngCount)
End If
Next
Application.ScreenUpdating = True

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Anthony" wrote:

i would like a code for autosort left to rigth
eg 1-3-5-7-3-8-4- "- represents blank cell"
1-3-3-4-5-7-8- leaving blank where they are

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 2007 sorting leaving blanks where they are left to rigth Anthony Excel Programming 0 November 5th 08 02:04 AM
Left, top, rigth and bottom points dimensions in a 3d Chart Edgar[_2_] Excel Programming 2 August 18th 08 10:16 PM
autosort left to right Anthony Excel Programming 0 July 25th 08 04:56 PM
set left rigth margins for header i need it wider to the edge of t Valentin Excel Discussion (Misc queries) 0 September 14th 05 11:01 AM
WHAT DO I MICROSOFT EXCEL IN THE RIGTH TO LEFT EXCEL CHARTS Charts and Charting in Excel 1 April 7th 05 03:48 PM


All times are GMT +1. The time now is 05:30 PM.

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"