+ Reply to Thread
Results 1 to 7 of 7

Sorting VBA doesn't work - Need advice

  1. #1
    Registered User
    Join Date
    03-16-2018
    Location
    London
    MS-Off Ver
    Office Excel 2013
    Posts
    4

    Sorting VBA doesn't work - Need advice

    Hi there,

    I have spent most of the afternoon looking for clue and reason why my code actually doesn't work.
    It should be simple but i don't get it

    Basically, what i just want to do is a Sort on R column, without headers, from Largest to Smallest amount.
    My code below doesn't work ! Interestingly, i don't have any error message, it just does nothing !

    Capturemacro.JPG

    Here is my code :
    Please Login or Register  to view this content.
    The line which has no effect is underlined

    This goal of this code is to copy paste all the lines which have a specific number (4), on a sheet called "Inma & sztoday" (sztoday is a string equal today's date).
    Some formula are added/
    Qlastrow is a variable equal the number of rows.

    I tried to activate the worksheet as i thought it could change something but no...

    I recorded a macro but i'm pretty sure it add too much useless lines...
    Please Login or Register  to view this content.
    Any help please ?
    Let me know if you need further details

    Many thanks,
    kenken1987

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,016

    Re: Sorting VBA doesn't work - Need advice

    .
    Sometimes recording a macro can be an easy method to obtain your answer and it is very valuable to do so because it becomes a learning tool.

    Suggestion: Take a blank workbook, add fake data to it like your real workbook. Use the recorded macro to sort Col R. Each time, remove one of the lines of code
    from the recorded macro and see what happens. Eventually you will have culled down the macro to the absolute smallest number of code lines and you will see
    what code works for the next time you need it.

    Then you can plug the resulting macro into your existing workbook.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Sorting VBA doesn't work - Need advice

    Why don't you upload a sample of your file so that someone can assist...
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Sorting VBA doesn't work - Need advice

    I'm not sure why you are specifying no header when you clearly do have a header row? I presume you have an On Error Resume Next somewhere in your code as that line should produce an error since you didn't qualify the sort column with the correct sheet
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Registered User
    Join Date
    03-16-2018
    Location
    London
    MS-Off Ver
    Office Excel 2013
    Posts
    4

    Re: Sorting VBA doesn't work - Need advice

    Hi guys,

    sintek: if this can helping you to assist me, i will next time

    I tried a little of everything you said guys, and i solved the issue.

    apparently, you can't sort range if your sheet has not been activated, or you are going to sort the ones on the original sheets you are on...

    This is the case here, an other sheet was activated, thanks to a line of code above which i didn't show (i am stupid...), and this is why it wasn't working but not crashing, it was actually sorting Cells on a other sheets !

    Here is 2 solution i found out to solve this :

    Add activate
    Please Login or Register  to view this content.
    or

    change the lines of sort, add the entire path on the key1 parameters, as below

    Please Login or Register  to view this content.
    Many thanks for your helps guys, i learn something today
    Kind regards,
    kenken1987

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Sorting VBA doesn't work - Need advice

    FYI, as I showed above, you don't need to repeat the sheet object since you're inside a With block using that sheet. You just need
    Please Login or Register  to view this content.
    Note the full stop before the word Range.

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,016

    Re: Sorting VBA doesn't work - Need advice

    .
    Glad you got it sorted out.

+ 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. [SOLVED] sorting race results into overall positions... any advice?
    By billyd333 in forum Excel General
    Replies: 9
    Last Post: 02-19-2018, 10:52 PM
  2. [SOLVED] Macro work in personal workbook, doesn't work in other workbooks
    By Centexcel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-30-2013, 11:47 AM
  3. [SOLVED] Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-27-2013, 11:55 AM
  4. General Advice (Filtering & Sorting)
    By demonfly100 in forum Excel General
    Replies: 0
    Last Post: 01-29-2013, 05:20 AM
  5. Sorting Rows Doesn't Work, Please Help
    By binar in forum Excel General
    Replies: 30
    Last Post: 08-09-2006, 04:39 PM
  6. Sorting numbers doesn't work correctly
    By GrammyEmmy in forum Excel - New Users/Basics
    Replies: 8
    Last Post: 06-25-2006, 06:50 PM
  7. Advice sought: Multiple column sorting
    By davidm in forum Excel Formulas & Functions
    Replies: 31
    Last Post: 09-06-2005, 06:05 PM

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