+ Reply to Thread
Results 1 to 6 of 6

Range/union

  1. #1
    Forum Contributor
    Join Date
    10-16-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    257

    Range/union

    Hi

    I tried to write a macros to delete multiple cells in a sheet, and only certain ones were cleared, so I ended up recording one and on some lines BEFORE it states RANGE it has UNION, it all works, but what does this mean and why did my way of doing it not delete certain cells. First example is my way, and second example is the recorder.
    I also noticed there is ACTIVATE there also?

    Thanks

    Please Login or Register  to view this content.




    And mine:

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Range/union

    In your macro (Sub satnightcleardown()) you clear only the second range. If you want to clear both ranges, either use Selection.ClearContents twice
    Please Login or Register  to view this content.
    or even better, don't use select at all:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    10-16-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    257

    Re: Range/union

    But don't the recorded macroselect different cells similar to what I have and use 1 selection clear.
    I have another macro that selects 9 different ranges on 4 different pages and uses the section clear once too.

    Thanks

  4. #4
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Range/union

    I have no idea why the macro you recorded translated into code like that. Let's go through it line by line.
    Please Login or Register  to view this content.
    This line is selecting more ranges with one range command. The underscore (_) means that the line is continuing in the next row. You probably selected this range while pressing Ctrl, right?
    Please Login or Register  to view this content.
    I think this is the last cell that you started selecting (S34), so it is now the active cell.
    Please Login or Register  to view this content.
    You selected another range with your mouse. Please note, that VBA forgets the selection before. Also note that the cells that were in the selection before are included in this selection as well. The Union part in this line is useless, I don't know why the recorder included it.
    Please Login or Register  to view this content.
    Erase the contents of the above selection.

  5. #5
    Forum Contributor
    Join Date
    10-16-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    257

    Re: Range/union

    Ok. I'll try out what you said then.
    As the recorder does look messy in my opinion, so I need to put a selection clear at the end BEFORE i would basically declare a new range.

  6. #6
    Forum Contributor
    Join Date
    10-16-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    257

    Re: Range/union

    Understand now! I can see exactly how the other workbook clears down now! I never had as many "RANGE" written in, just the once with multiple cells, then there is a clear selection before each page selection.

    Thanks alot!

+ 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