+ Reply to Thread
Results 1 to 18 of 18

Need Help with Sorting a Range on Hidden Columns

  1. #1
    Registered User
    Join Date
    09-06-2018
    Location
    İstanbul
    MS-Off Ver
    2013
    Posts
    8

    Question Need Help with Sorting a Range on Hidden Columns

    Hello all,

    I have a trouble with sorting data on hidden columns in the same sheet. I can not sort the data since it is hidden.

    I thought that it is caused by Goto method but I also tried this without selecting and it does not fixed. Is there any way to sorting the hidden column on the same sheet? Here is my code below:


    Application.Goto Reference:="SiralaGRF1", scroll:=False
    ActiveWorkbook.Worksheets("Gösterge Paneli").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Gösterge Paneli").Sort.SortFields.Add Key:=Range( _
    "W8:AL8"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.Worksheets("Gösterge Paneli").Sort
    .SetRange Range("W6:AL8")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlLeftToRight
    .SortMethod = xlPinYin
    .Apply
    End With


    Thanks for your help!

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Need Help with Sorting a Range on Hidden Columns

    Unhide all, sort and then hide them again?
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    09-06-2018
    Location
    İstanbul
    MS-Off Ver
    2013
    Posts
    8

    Re: Need Help with Sorting a Range on Hidden Columns

    Thanks for your interest. Since my data is big, unhiding and hiding columns every time makes it work slowly and inconsistent. I need something different I guess.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Need Help with Sorting a Range on Hidden Columns

    You don't mention which of those columns is hidden. But, in my testing, a column being hidden doesn't effect sorting, either on that column or on some other column. It might effect Selecting the whole range (if the hidden column is at the edge of the range to sort, its hard to select it with a mouse.)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    09-06-2018
    Location
    İstanbul
    MS-Off Ver
    2013
    Posts
    8

    Re: Need Help with Sorting a Range on Hidden Columns

    Oh, your right I forgot to mention it. All columns are hidden except A:Q , and my reference (SiralaGRF1) that constains my data to be sorted is on the range ("W6:AL8") and sorting will be done according to W8:AL8 .
    But i could not sort them with vba when the columns are hidden how did you test it?

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Need Help with Sorting a Range on Hidden Columns

    Both Manually and with code like

    Please Login or Register  to view this content.
    I notice that you sort range starts on column W, so that code won't sort columns A:V hidden or un-hidden

  7. #7
    Registered User
    Join Date
    09-06-2018
    Location
    İstanbul
    MS-Off Ver
    2013
    Posts
    8

    Re: Need Help with Sorting a Range on Hidden Columns

    Yes, I am using the data for my graph. So I want to hide my data. But when it is on hidden columns, code does not sort it

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Need Help with Sorting a Range on Hidden Columns

    I can't replicate your error. Can you post a (desensitized, not huge) workbook that shows the error.

  9. #9
    Registered User
    Join Date
    09-06-2018
    Location
    İstanbul
    MS-Off Ver
    2013
    Posts
    8

    Re: Need Help with Sorting a Range on Hidden Columns

    Here is a example workbook. I assigned macro to formbox. When I hide the graph value (column I:L) code does not work. Actually it does not gives error, code just does not work.
    Attached Files Attached Files

  10. #10
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Need Help with Sorting a Range on Hidden Columns

    I’m not at my computer now but will look later

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Need Help with Sorting a Range on Hidden Columns

    I was able to log in remotely
    The macro Sort4 you have in your file does not won't sort anything outside the range I4:L6 so what is this with columns W and hidden columns.
    If that need sorting too, there is nothing in this code that does that.
    I suggest you either explain it better or review your macro code or explain it in a way someone that has no idea of what you're trying to achieve can understand too.
    That is the most difficult part, asking the question in such a manner that others may understand and of coures we have to do our best to expplain it so that others understand

    Please Login or Register  to view this content.
    Keep in mind that when you want to sort an entire range you must include that whole range in your macro!

  12. #12
    Registered User
    Join Date
    09-06-2018
    Location
    İstanbul
    MS-Off Ver
    2013
    Posts
    8

    Re: Need Help with Sorting a Range on Hidden Columns

    You'r right, let me try to explain my issue more clear.
    Sheet 2 is my data page, and I just have different datas based on years on sheet 2.
    I want to create a dashboard on sheet 1. I just want to see specific dashboard area. Everything else must be hidden, which means range (columns H:XFD) and (rows 18:1048576) will be hidden.
    On the other hand, I have created a graph. And for a better pattern, data must be sorted in descending order. To do so, I replicate my data on sheet 2 to sheet 1. The area is I4:L6 . I want to sort this area. For this purpose I created the macro above and assigned it to listbox. When user click on the listbox for changing the year, data on I4:L6 will be changed and macro will sort the data. Graph takes the data on I4:L6 .
    When I don't hide the columns, macro runs perfectly and sorts the data. But if I hide the columns, macro does not sort the data.
    To sum up, my purpose is sorting the data which is located on hidden columns. Thanks again for your help.

  13. #13
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Need Help with Sorting a Range on Hidden Columns

    Okay, clear, then the hidden columns to the right of column L have no play in this and it's merely to hide them from view.
    Let me see if I get it to work

  14. #14
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Need Help with Sorting a Range on Hidden Columns

    Well, I hid all the columns and the second sheet too, and the sorting when I change the year works great and I made no changes,
    I do not see what the problem is.
    The list in column a I did nothing with that one
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    09-06-2018
    Location
    İstanbul
    MS-Off Ver
    2013
    Posts
    8

    Re: Need Help with Sorting a Range on Hidden Columns

    sort 2017.jpgsort 2018.jpg

    It still does not work in my pc, maybe it caused by the version difference. You can see the images above,
    on second image (2018) c has the biggest value but it is on the third place. Pattern must had be like 2017.

    Anyway, I appreciate for your effort, thanks a lot.

  16. #16
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Need Help with Sorting a Range on Hidden Columns

    I didn't have the time to upload.
    Try this.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    09-06-2018
    Location
    İstanbul
    MS-Off Ver
    2013
    Posts
    8

    Re: Need Help with Sorting a Range on Hidden Columns

    I avoid from unhiding-hiding because my real file is much bigger and if I do it that way, there is about 4 seconds lag on the file. But only way is unhiding and hiding again I guess. Thank you Keebellah

  18. #18
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Need Help with Sorting a Range on Hidden Columns

    I don't know how great the lag is but hiding and un-hiding these 4 columns does not require much, it's the time loading your rows of data in sheet2 probably.
    If so then add extra like disable events, calculation etc to speed it up.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Difficulty Emailing a Range Without Exposing the Hidden Columns
    By e648364 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2017, 03:39 PM
  2. [SOLVED] Only specific columns are hidden based on range
    By biznez in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-05-2017, 01:35 PM
  3. I need to select a range and skip over the hidden columns
    By morangeman in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-06-2014, 09:29 PM
  4. Replies: 0
    Last Post: 01-15-2014, 05:17 PM
  5. Replies: 0
    Last Post: 09-13-2012, 11:10 AM
  6. [SOLVED] Hide columns based on cell value - Unable to set hidden range property of Range Class
    By trillium in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-13-2012, 11:13 PM
  7. Range.Value doesn't work in hidden columns
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2006, 03:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1