+ Reply to Thread
Results 1 to 20 of 20

Current VBA code acts up

  1. #1
    Registered User
    Join Date
    11-14-2018
    Location
    Colorado
    MS-Off Ver
    365
    Posts
    16

    Question Current VBA code acts up

    Hello,

    I have an existing macro I pieced together in VBA. It works most of the time, but sometimes does weird stuff. Wondering if there was a cleaner way to perform all these functions. Any help is appreciated!

    Here is current code:

    Please Login or Register  to view this content.
    Each function broken down, including things not currently in code:
    Ignore first row, this is column headers and should be left untouched
    Go through column A and delete any rows > 60000000 and < 80000000
    Go through column C and delete any rows that contain values. Any rows with blank cells in column C should not be deleted.
    Go through column V and delete any rows that contain values. Any rows with blank cells in column V should not be deleted.
    Convert all cells in column K to numbers

    What do you all think?

    Thanks!
    Last edited by MrLukeSkyGuy; 01-25-2019 at 08:18 PM. Reason: add code tags

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Current VBA code acts up

    Hi, please wrap your code in
    Please Login or Register  to view this content.
    tags per forum rules-

    https://www.excelforum.com/forum-rul...rum-rules.html

  3. #3
    Registered User
    Join Date
    11-14-2018
    Location
    Colorado
    MS-Off Ver
    365
    Posts
    16

    Re: Current VBA code acts up

    Apologies, fixed!

  4. #4
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Current VBA code acts up

    Hiya, thanks!! Try this code out...

    Please Login or Register  to view this content.
    Last edited by 1aaaaaaaaaaaaaaa; 01-18-2019 at 02:43 PM.

  5. #5
    Registered User
    Join Date
    11-14-2018
    Location
    Colorado
    MS-Off Ver
    365
    Posts
    16

    Re: Current VBA code acts up

    Hello,

    It is erroring on this line:

    Please Login or Register  to view this content.
    Error # 1004
    Method 'Union' of object '_Global' failed.

    Any ideas?

    Thanks!
    Luke

  6. #6
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Current VBA code acts up

    Try changing to

    Please Login or Register  to view this content.
    Last edited by 1aaaaaaaaaaaaaaa; 01-25-2019 at 01:42 PM.

  7. #7
    Registered User
    Join Date
    11-14-2018
    Location
    Colorado
    MS-Off Ver
    365
    Posts
    16

    Re: Current VBA code acts up

    Same error

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,079

    Re: Current VBA code acts up

    How about
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-14-2018
    Location
    Colorado
    MS-Off Ver
    365
    Posts
    16

    Re: Current VBA code acts up

    Same error still

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,079

    Re: Current VBA code acts up

    Do you have any merged cells?
    Also is the sheet protected, or hidden?

  11. #11
    Registered User
    Join Date
    11-14-2018
    Location
    Colorado
    MS-Off Ver
    365
    Posts
    16

    Re: Current VBA code acts up

    No merged cells, not protected nor hidden. The data is created using access and dumped into this tab. There are several other tabs, but I changed the ws to the one being manipulated. Set ws = Sheets("Retail Report Data")

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,079

    Re: Current VBA code acts up

    Can you supply a copy of your workbook?
    It will make it a lot easier to debug.

  13. #13
    Registered User
    Join Date
    11-14-2018
    Location
    Colorado
    MS-Off Ver
    365
    Posts
    16

    Re: Current VBA code acts up

    Yes, here you go! Thank you for your help btw

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,079

    Re: Current VBA code acts up

    There's nothing attached

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  15. #15
    Registered User
    Join Date
    11-14-2018
    Location
    Colorado
    MS-Off Ver
    365
    Posts
    16

    Re: Current VBA code acts up

    Sorry file was too big. Cut out other tabs not being used.
    Attached Files Attached Files

  16. #16
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,079

    Re: Current VBA code acts up

    Thanks for that, try
    Please Login or Register  to view this content.

  17. #17
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Current VBA code acts up

    Sorry sir, that was buggy code on my part,

    move the rng.delete outside of the For loop

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    11-14-2018
    Location
    Colorado
    MS-Off Ver
    365
    Posts
    16

    Re: Current VBA code acts up

    You guys rock! This code did the trick and now the macro is performing exactly as needed. WAY better than my scrapped together version. I appreciate your time, you sure will save lots of mine moving forward!

  19. #19
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,079

    Re: Current VBA code acts up

    Glad we could help & thanks for the feedback

  20. #20
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Current VBA code acts up

    Late to the party but you might want to have a look at this alternative. It uses AutoFilter rather than looping. It takes about 1 second to run with your test file.

    Please Login or Register  to view this content.
    Can't post the code here as Sucuri dosn't seem happy about something
    Attached Files Attached Files
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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] Simple VBA code to convert text to number (simplify/fix current code)
    By kenenthpaul0401 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-26-2018, 10:47 AM
  2. [SOLVED] Set PivotTable Filter to Current Day, Current Week, Current Month, or Current Year
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2014, 08:31 AM
  3. [SOLVED] VBA code to save current worksheet as temporary PDF file and then add to my existing code
    By brianfromla in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-20-2014, 08:35 AM
  4. Code to insert current date (but NOT current time)
    By mjwillyone in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2013, 09:37 AM
  5. [SOLVED] add current time (hh:mm:ss) as well as current date (dd:mm:yyyy) into the code
    By papasideris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2012, 02:29 PM
  6. [SOLVED] When code runs...worksheet acts a little strange
    By KimberlyC in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-01-2005, 12:06 PM
  7. It looks and acts like a Comment but it's not.
    By CharlieT424 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-11-2005, 05:06 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