+ Reply to Thread
Results 1 to 18 of 18

VBA Macro programming variable sized range.

  1. #1
    Registered User
    Join Date
    08-12-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    47

    VBA Macro programming variable sized range.

    Hi Group, I'm not sure how to describe my problem so I'll do my best to explain what I'm trying to find out how to do it. I have a range of numbers which consists of anywhere from 27000 rows to over 500000 rows of data which I run a macro on that allows me to scan for duplicate numbers in rows and remove that row. Anyhow, when the macro is running it can take quite a while to run, sometimes over a day. What I would like to do is put the whole range from the spreadsheet in an array, and run the program on the array and then transpose it back to the spreadsheet. This method is suppose to be faster because of the time saved from updating the spreadsheet as it goes. I've already used the <Applications.Screenupdating> command in hopes to speed it up a bit but I'm still have long running times. How can I use VBA to find the limits of whatever range is in the spreadsheet and enter it into an array for the macro to run on it and then past the results back into the spreadsheet. I know it has something to do with using UBound and LBound but I am not sure how to configure it. Any help would be appreciated.

    Thank you.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA Macro programming variable sized range.

    Can't you just use Excel's deduplicate tool from the Data menu?

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: VBA Macro programming variable sized range.

    What about something like this?

    Please Login or Register  to view this content.
    I ran it on over 475k records and it return the results in seconds.
    HTH
    Regards, Jeff

  4. #4
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: VBA Macro programming variable sized range.

    Maybe is this a solution to you @sgrondines.
    http://www.excelforum.com/excel-prog...plicate-s.html
    Kind regards, Harry.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Macro programming variable sized range.

    Jef,
    You can use
    Please Login or Register  to view this content.
    in excel 2007, but not 2003? Am I right?

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: VBA Macro programming variable sized range.

    @AB33,

    Could be, I don't have 2003 and the OP showed 2007.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Macro programming variable sized range.

    Jef,
    I can not remember exactly where I have read, or seen it, but RemoveDuplicates Columns:=1, Header:=xlYes is new 2010 only. My mind was set on this assumption. I have excel 2010 and had not tested it in 2007. Now, seeing it you use it in 2007, my assumption was wrong, hence the reason for asking.

  8. #8
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: VBA Macro programming variable sized range.

    You're right @AB33.

    This methode is available from Excel 2007.

  9. #9
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: VBA Macro programming variable sized range.

    Yes, I am using 2007 and it works for 2007.

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520
    Can u upload a small sample of you wb and show the layout of your worksheet. And what column/ columns to look for duplicates in?
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Macro programming variable sized range.

    Jeff and Harry!
    Thank you for clarifying!

  12. #12
    Registered User
    Join Date
    08-12-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: VBA Macro programming variable sized range.

    No I don't think you guys got the gist of what I was asking. I'm just looking for the code to put the data on a worksheet into an array so that it will run faster when running the macro on the array instead of the cell by cell information on the spreadsheet. The code for putting the data from the spreadsheet into the array has to be able to identify the size of the data automatically. That's why I thought that maybe UBound and LBound could be used in the code to determing the size of the data in the worksheet. Currently, the code in the macro I set up looks at each individual cell in the rows and compares them to the next cell in the row looking for a certain criteria. If it doesn't meet that criteria it deletes that row. Problem is, is that there maybe up to 500,000 rows or more of data in the worksheet and the program has to go through each row from the bottom to the top of the worksheet and delete rows that don't meet my criteria. This can take more that a day of continuous running. I heard that if the data is processed in an array that the speed of the macro may be considerable. The results from the array can then be copied back onto the worksheet.

    Hope this explanation makes things clearer.

    Thanks.

  13. #13
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: VBA Macro programming variable sized range.

    Can you post a small sample of your workbook? And the code you are using?

  14. #14
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: VBA Macro programming variable sized range.

    I think we understood your question, but I think you may have missed the request in post #10 (and now #13 ).

    Please include a before and after and where you want the results. A day to run the macro Please let us see what you have done so far.
    Last edited by jeffreybrown; 12-30-2012 at 08:13 PM.

  15. #15
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA Macro programming variable sized range.

    We get the gist of what you're saying, but what we're trying to tell you is that loops, be they through ranges or through arrays, are inherently slow.

    If you can use Excel's native de-dupe functionality then it will be hundreds of times faster, not a few percent faster. If there's a reason that you can't just de-dupe the sheet then tell us what it is and we'll try to work around it.

  16. #16
    Registered User
    Join Date
    08-12-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: VBA Macro programming variable sized range.

    I'm sorry I don't know how to explain it any better than what I just did without posting all my data and and the program which I don't feel like doing right now. I'm sorry you couldn't help.

    Thanks anyhow.

  17. #17
    Registered User
    Join Date
    08-12-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: VBA Macro programming variable sized range.

    PS. How do I close a thread without marking it as solved?

  18. #18
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: VBA Macro programming variable sized range.

    Just leave it as is...that is fine

    P.S. You could just post some sample data. It doesn't have to be the whole 500,000 lines of data, just a good representation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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