+ Reply to Thread
Results 1 to 50 of 50

Macro to sort and delete cells

  1. #1
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Macro to sort and delete cells

    Hi All

    Attached is my cut down file, in Cell A2 we have a formulae that selects the data I need, I now need a MACRO to sort column A by Low to High,
    then delete the ROWS that have ZERO data, as the file stands now it will start with VK1RAN finishing with VK9RRR, these could change if new data is registered.


    Peter
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor than_gold's Avatar
    Join Date
    10-17-2017
    Location
    Coimbatore India
    MS-Off Ver
    Office 365
    Posts
    646

    Re: Macro to sort and delete cells

    Here you go:
    Please Login or Register  to view this content.
    Regards,
    Thangavel D

    Appreciate the help? CLICK *

  3. #3
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Please Login or Register  to view this content.



    The cells I am sorting is A2 to E####### umpteen thousands
    Last edited by Potholes; 06-29-2018 at 11:19 PM.

  4. #4
    Valued Forum Contributor than_gold's Avatar
    Join Date
    10-17-2017
    Location
    Coimbatore India
    MS-Off Ver
    Office 365
    Posts
    646

    Re: Macro to sort and delete cells

    Please Login or Register  to view this content.
    Please make this change & check.

  5. #5
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Please Login or Register  to view this content.
    Last edited by Potholes; 06-29-2018 at 11:18 PM.

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Macro to sort and delete cells

    Use Report Post to ask moderator to move this thread to appropriate sub-forum
    Use code tags for your code: [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE]

  7. #7
    Valued Forum Contributor than_gold's Avatar
    Join Date
    10-17-2017
    Location
    Coimbatore India
    MS-Off Ver
    Office 365
    Posts
    646

    Re: Macro to sort and delete cells

    Here its working fine...i'm using Office 365. Which version is you are checking?
    Attached Files Attached Files

  8. #8
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    My code is reporting the error as shown below

    Please Login or Register  to view this content.
    Last edited by Potholes; 06-29-2018 at 11:10 PM. Reason: Possible code violation

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,444

    Re: Macro to sort and delete cells

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  10. #10
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    is this what you are after ??


    Please Login or Register  to view this content.
    Last edited by Potholes; 06-29-2018 at 11:17 PM.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Code tag should use [ ], not ( )
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]

  12. #12
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    is this what you are after ??


    Please Login or Register  to view this content.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Correct and please edit all your posts as well.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Thanks for the code tag and here's a simple code.
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Hi Jindon

    Thank you for that code however when I run it it also deleted my Macro command button

    File attached
    Attached Files Attached Files
    Last edited by Potholes; 06-29-2018 at 11:39 PM. Reason: Code erros

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    What kind of button is it?

    Can you upload a workbook with the button?

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    I didn't notice that you have uploaded new workbook...

    1) Right click on the shape and asign macro "test"
    2) Right click on the shape and Properties tab and choose "Don't move or size with cells"

    should solve the problem.

  18. #18
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Hi Jindon

    Thank you for that code

    My actual data base is 900,000 rows by about 60 columns wide, do you think your code will work ok ???

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Should work but take a while...

    Due to a formula, better to control Calculation mode off/on. like
    Please Login or Register  to view this content.

  20. #20
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Hi again


    Please Login or Register  to view this content.

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    No error...............
    Attached Files Attached Files

  22. #22
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Please Login or Register  to view this content.

  23. #23
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,444

    Re: Macro to sort and delete cells

    Potholes - it would be useful to add a comment to each post with code so that we know why you have posted it and to give members a clue as to what they are looking for.

  24. #24
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Hi me the pain in the BUTT again.

    I tried the macro on my main database which goes from column A through to column BF and 900,000 rows.

    The macro stops at with the AutoFilter high lighted in yellow

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

  25. #25
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Which code are you talking about?

    Did you write that code for yourself?

  26. #26
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    This is the code I extracted from your file which I downloaded
    NO I did not write any code the only change I did was here {Range("A:BF").Sort } to change the column out to BF

    My master file is A to BF and is actually 1,200,000 rows

    Please Login or Register  to view this content.

  27. #27
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    That's YOUR FILE with my code added.

    Formula in Col.A goes to entire column?
    Please Login or Register  to view this content.

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

    Re: Macro to sort and delete cells

    So...Move your button to top row...
    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!!!

  29. #29
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Garbage deleted.
    Attached Files Attached Files

  30. #30
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Quote Originally Posted by jindon View Post
    Garbage deleted.
    Good afternoon

    If you are still able to assist me great, sometimes my 80 year old brain takes leave of me.

    In your code below you have a line that I am not sure of iy's function.:-

    Please Login or Register  to view this content.

    My data base is 1,400,000 rows by columns A to BF



    Peter

  31. #31
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Quote Originally Posted by Potholes View Post
    My data base is 1,400,000 rows by columns A to BF
    Total number of rows in a column = 1,048,576

    Simply IMPOSSIBLE.

  32. #32
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Hi

    That explains why the error message when opening the original .CSV which I download from the Australian Govt website, Soooooo I am missing a lot potential data..

    I checked my data file and yes it is 1,048,576

    The things we learn every day Ehhhh

    Bugger..
    Last edited by Potholes; 07-01-2018 at 03:14 AM.

  33. #33
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Only the way is to read the data directly from CSV(Text file) and manipulate within memory.

  34. #34
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Hi all

    I am NOT starting another post, just putting up where I am up to ATM, hoping to catch Jindon..

    I have a .csv data base that has 1,400,000 rows and 55 columns. Using a text editor I have opened the csv file and copied
    about 50% to a Excel sheet called Data_1 and the remainder off to Data_2. I have attached a file called Book_2
    which is the smallest file allowable to upload.

    I had guru (jindon) help me with some code for a Macro which is below,:-

    Please Login or Register  to view this content.
    What I need is the macro to sort column A ( to only find data that is VKx
    (any number between 0 to 9) and the 3 following letters starting with R and only like eg:-
    VK4RLW VK1RIG VK3RTT etc, it needs to ignore eg:- VK5RR VK1RZ etc, at the moment when I run
    the macro on each sheet it only sorts column A from Lowest to highest, and showing the data
    I need, atm it deletes the header row which I need to keep.

    Any help would be appreciated..

    Peter
    Attached Files Attached Files

  35. #35
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,444

    Re: Macro to sort and delete cells

    You have started (and finished) another POST, but not another THREAD - thank you for not starting another thread.

  36. #36
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Hi Have done right or wrong please. ???

  37. #37
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,444

    Re: Macro to sort and delete cells

    Thank you = right.

    Post = individual message within a thread.
    Thread = chain of posts (messages) within a forum query.

  38. #38
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    In order to read diretly from csv, I need to see csv (text file).

    I'm not with mt pc, so if upload the file, I can write a code when I come back.

    Sending this from phone.

  39. #39
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Hi

    The .CSV file is 200.4 meg so I cannot upload here.

    Pete

  40. #40
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    No that much.
    Just about first 20 - 30 lines shoild be Ok, incding header if it has.

  41. #41
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    The book_2.xlsm file that I have uploaded has the header and 13,000 + rows, contains the 55 columns, with the header.

  42. #42
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Ok, I'll see when I come back.

  43. #43
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Good evening

    I have attached the current file with ALL of the columns, some were missing off the previous file from today.

    Peter
    Attached Files Attached Files

  44. #44
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Tested and extracted 155 records based on your book, so test this with your actual csv.
    If extracted rows still exceed the number of rows in Excel, it will output as CSV in the same folder.
    Please Login or Register  to view this content.

  45. #45
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    Hi I can't open the whole CSV file in excel as it is too big and I am not sure how to use your macro in conjunction with the csv file

  46. #46
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Just select the original csv file.

    CSV file and Excel workbook is totally different.
    Excel CAN open csv, but csv file is a comma delimited TEXT file.

    You know what I mean?

    If you right click on csv file and open with notepad, you will see actual contents.

  47. #47
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    Book2.csv is the file converted and saved as csv from Book2.xlsm you uploaded.
    So, select above file when the dialog comes up.
    Attached Files Attached Files

  48. #48
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: Macro to sort and delete cells

    The file I uploaded to you is HALF of the full CSV file, the
    Data_1 page has 1,008,654 rows 55 columns
    Data_2 page has 16,673 rows 55 columns it is this one I uploaded known as Book_2.xlsm

    So I am unsure where to go from here.

  49. #49
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    You are talking bout Excel workbook.

    CSV file can not have more than 1 page...

    OK, tell me where original csv file which has 1,400,000 rows come from?
    Do you have original csv file?

  50. #50
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Macro to sort and delete cells

    After several PM exchange, now OP's request is clear.
    Get data from CSV where value in CALL_SIGN column is like VK#R & 2 alphabets or more.
    Move CALL_SIGN column to the first and sort by CALL_SIGN.
    Create a new csv file in the same folder.
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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. Replies: 3
    Last Post: 12-15-2017, 05:30 AM
  2. [SOLVED] Macro Sort, move, delete
    By memoe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-25-2014, 04:13 PM
  3. Macro to Sum, Delete, and Sort
    By L-R in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2013, 04:42 PM
  4. [SOLVED] Help with a macro to delete empty (but not blank) cells OR sort blanks to the bottom
    By Cyali in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2012, 09:04 PM
  5. macro to sort and delete certain rows?
    By gtiguy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-02-2012, 05:20 PM
  6. macro to delete rows and sort
    By jrtaylor in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-29-2009, 11:11 AM
  7. Delete empty cells and custom sort by group?
    By iturnrocks in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-17-2008, 03:19 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