Sortng data with rows of differnt heights. etc

Mabocat

Board Regular
Joined
Apr 20, 2011
Messages
74
I have a spreadsheet page made of 14 columns and on average 60 rows - some are standard height & others larger and is planned to be sorted on a time of hours & minutes based on one column.
Currently I cut and paste the rows because i had merged cells. After reformatting the cells, I now have a macro that sorts the data OK but the row formatting of height is ruined.

Is it possible to sort data ( meaning the rows) and maintain the row formatting ? if so, what do I do to change my macro
Code:
     With Worksheets("Tawnton")
       .Sort.SortFields.Clear
    .Sort.SortFields.Add Key:=Range("Tawnton_time"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With .Sort
      .SetRange Range("Tawnton_data")
      .Header = xlGuess
      .Orientation = xlTopToBottom
      .Apply

Ron

PS sorry for spelling errors in Subject - unable to edit it.
 
Last edited:
The word Set which is in the next line of code
Code:
   If Left(Trim(cel), 3) = "Set" Then cel.RowHeight = 30

does not start at the beginning of the cell in column E but at least 4 spaces in from left hand side of the cell.
Would this affect it?
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
The word Set which is in the next line of code
Code:
   If Left(Trim(cel), 3) = "Set" Then cel.RowHeight = 30

does not start at the beginning of the cell in column E but at least 4 spaces in from left hand side of the cell.
Would this affect it?

No - Trim(cel) takes care of that.
 
Upvote 0
It stops here and the error box has it " The item with the specified name wasn't found" but not being able to see it working on the page, I am guessing
I copied your coding straight into my file
Code:
For Each cel In Intersect(Range("Tawnton_data"), [E:E])

" The item with the specified name wasn't found"
Must be something wrong with : Range("Tawnton_data").
On the file I downloaded there is nothing wrong.
 
Upvote 0
When I manually sort- using the range name Tawnton_data , it works without any problems
this is the full coding
Code:
      With Worksheets("Tawnton")
       .Sort.SortFields.Clear
   .Sort.SortFields.Add Key:=Range("Tawnton_time"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  With .Sort
  .SetRange Range("Tawnton_data")
    .Header = xlNo
      .Orientation = xlTopToBottom
     .Apply
'      Application.Goto Reference:="Tawnton_home"
'     Application.Goto Reference:="Charde_home"
      End With
      End With
      ThisWorkbook.Save
Dim cel As Range
With Worksheets("Tawnton")
    Range("Tawnton_data").RowHeight = 16.25
    For Each cel In Intersect(Range("Tawnton_data"), [E:E])
        If Left(Trim(cel), 3) = "Set" Then cel.RowHeight = 30
    Next


and prior to me adding your suggested coding, it sorted OK but leaving row heights no good.

and how do I step through a macro so it shows what it is actually doing on the spreadsheet - that is moving around the page?
 
Upvote 0
Change to this :
Code:
With Worksheets("Tawnton")
    .Range("Tawnton_data").RowHeight = 16.25
    For Each cel In Intersect(.Range("Tawnton_data"), .[E:E])
        If Left(Trim(cel), 3) = "Set" Then cel.RowHeight = 30
    Next

how do I step through a macro so it shows what it is actually doing on the spreadsheet - that is moving around the page?
By pressing F8
 
Upvote 0
I do press F8 & step through the macro instructions but it still does not show me on the actual spreadsheet page, it moving around selecting ranges etc & showing the various dialog boxes but that is a minor point - my sort problem is the main aspect.
I may try to run it as a separate macro activity.
 
Upvote 0
I do press F8 & step through the macro instructions but it still does not show me on the actual spreadsheet page, it moving around selecting ranges etc & showing the various dialog boxes
It will only take you to a sheet so you can see what's going on if the code activates the sheet.
You could do it by manually selecting the appropriate sheet as you step through the code.
 
Last edited:
Upvote 0
It takes me to the sheet but does not go to the various ranges nor show the various dialog/input boxes .

Anyway I now have time to try your code as a separate macro.
 
Upvote 0
It takes me to the sheet but does not go to the various ranges nor show the various dialog/input boxes .
I really cannot comment without knowing exactly what you are doing or what code you are referring to.
 
Upvote 0
when I am in Edit mode & F8 to step thru macro and have screen show exactly what happens, I want to see all the actions of selecting the various ranges, have the Sort data input box show , etc and even with your code, to step row by row to test for the word "Set" and show the row height box being changed from the basic 16.25 to 30.

I got your code working separately but the arrows don't move with the row, even though they are set to move with cells being in column L
 
Upvote 0

Forum statistics

Threads
1,215,223
Messages
6,123,711
Members
449,118
Latest member
MichealRed

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top