View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
Myrna Larson[_2_] Myrna Larson[_2_] is offline
external usenet poster
 
Posts: 124
Default INSERTING ROWS WITH A MACRO

Sounds to me like there are two critical questions:

1. How do you know where the block changes? Is there a delimiter between them, as you show in
the message?

2. How do you know what the dates are supposed to be in each block?

Here are some "issues" that have to be dealt with:

If the 1st block included dates 9/10 through 9/15 -- 6 dates -- how would one know whether the
first one or the last one is missing? i.e. is the block supposed to be 9/10 through 9/16, or 9/9
through 9/15?

I considered finding the minimum date and assuming it's the 1st date, and the maximum and
assuming it's the 7th. But it's theoretically possible that the 1st date was missing from ALL
blocks, or the last date is missing from all blocks. e.g. if the earliest date in the column was
9/2 and the latest 9/7, how would you know whether it's 9/1 that's missing or 9/8?

I think you need to have

1. an identifiable block delimiter

2. the dates within a block are sorted (if they aren't, would you expect the code to sort them?)

3. a list of expected dates is somewhere else on the worksheet (or the code could throw up an
input box that asks for the first date)

If those requirements are met, the code is relatively straight-forward: find the next block
delimiter, then the one after it, check that they are 8 rows apart and all seven required dates
are present, in order, in the rows between. Repeat those steps until the end of the data in
column A.

In fact, without the block delimiter and the list of valid dates, there are far too many
assumptions that would have to be made in the code.

--------------------------------------------------------------
9/10/03
9/11/03 Let's call this set of 7 successive dates "Block 1".
9/12/03
9/13/03 ** Note:
9/14/03 By 7 successive dates, I mean if you count the dates
9/15/03 in this block (enclosed by lines) they are 7 in number.
9/16/03
---------------------------------------------------------------
9/10/03
9/11/03
9/12/03
9/13/03 Let's call this set of 7 dates "Block 2 "
9/14/03
9/15/03
9/16/03
------------------------------------------------------------
9/10/03
9/11/03
9/12/03
9/13/03 This one "Block 3"
9/14/03
9/15/03
9/16/03
------------------------------------------------------------

-- The report could contain any number of these "blocks".

* As you can see, each "Block" has two distinct properties:

** (1) The *number* of dates in each *Block* is 7.

** (2) The set of successive dates in each "Block" are the same dates,
regardless of what dates they may be.

-- I want a macro that will loop through the date column of each
"block" of cells. If the macro finds that in any "block" there are
missing dates then it should insert blank rows and update the dates.

** As an example-- Suppose there is a "Block 4" below "Block 3" in the
above illustration which looks like
------------------------------------------------------------
9/10/03
9/11/03
9/14/03 "Block 4"
9/15/03
9/16/03
------------------------------------------------------------

** We see that "Block 4 " has 5 number of dates instead of 7 number
of dates. Its dates column is missing 9/12/03 and 9/13/03. So, when
the macro loops through "Block 4", it will insert 2 blank rows between
9/11/03 and 9/14/03, then update the block with those two dates. That
way "Block 4" becomes like the below with 7 number of dates
------------------------------------------------------------
9/10/03
9/11/03
9/12/03----inserted row by macro
9/13/03---- inserted row by macro
9/14/03
9/15/03 "Corrected Block 4"
9/16/03
------------------------------------------------------------

**In the same way,the macro would "scan" through the date column of
all existing "Blocks" and for any missing dates, insert equivalent
number of rows and update the dates column.**

-- In the end, every "Block" would contain 7 number of dates. The
dates will still be the same serial number for every "Block".

-- On the other hand, if the macro loops through all the date columns
and finds that every "Block" contains 7 dates, of the same serial
number, then it won't have to do anything.

Please pardon me. I am not too good at making myself clear and I
hope the above illustration clarifies what I am trying to seek help
with. Again, sorry for any confusion and contradiction. Thanks.

Jay Dean