View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Matthew Herbert[_3_] Matthew Herbert[_3_] is offline
external usenet poster
 
Posts: 149
Default empty buffer for new iteration

Steve,

Are you saying that you want TopCell to be reset if you move to the next
column after searching the rows? You have the "verbage" to reset the object
in the code, i.e. Nothing. A range is an object, and objects are cleared
from memory (i.e. "reset") with the Nothing keyword. (Both ToCell and
BotCell are dimensioned as Range). If you want TopCell "reset" after each
column then add "TopCell = Nothing" prior to your "Next iCol" statement (also
shown below); otherwise, put the statment where you need it to go.

Also, you can test your code by debugging it (Debug | Step Into) via the F8
key. Hit F8 repeatedly, hover the cursor over your variables, watch the
Excel window as you hit F8, etc. Additionally, you can add Debug.Print
statements and view the Immediate Window (View | Immediate Window). For
example, you can add "If Not TopCell Is Nothing Then Debug.Print
TopCell.Address" to see the address of TopCell, or simply put "Debug.Print
..Cells(iRow, iCol).Address" somewhere within the code to see where you are in
the loop.

Next iRow
TopCell = Nothing
Next iCol

Best,

Matthew Herbert

"Steve" wrote:

Morning all.
Back in July I was having a conversation with Dave Peterson regarding the
merging of cells. All of the code, etc... is at this link.

http://www.microsoft.com/communities...4-4ad88ee76d9f

As I have worked through his code sample, I found that I ran across an issue
I wasn't anticipating.
It appears that the TopCell variable remains as a constant, and each new
BotCell variable is the variant. This results in my merged cell group growing
by the location of the botcell.
I.e., say that I start TopCell at a10. BotCell drops by 4 with each new
iteration. When my IF criteria are located, instead of TopCell being
relocated for each new iteration it remains at A10, and everything from
TopCell to BotCell is merged.
In the end, I get a merged cell group that is 1000's of rows in size. In
spite of my criteria stated in the IF EQ's.

My intention was to have the buffer emptied for TopCell, and BotCell, so
that they'd find the next set of criteria, and perform the group merge that I
want. It appears that the BotCell is indeed reset, but the TopCell remains at
its original position.

I have if eq's set to look for row border types. If the border is found at
the top of the cell, use that as my TopCell. it then looks for either a
bottom or a top border. If it finds a bottom border, it sets that as the
BotCell.

What verbage/term/phrase do I need to empty/reset the buffer for both
TopCell, and BotCell?

Thank you.