Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Formulas are skipping a row

Hello,

I picked up some VBA that inserts a row, then copies the values down
from the row above to the new row, then keeps only those values in the
new row that contain formulas:

Sheets("IDA MI WrkGrp Rpt").Select
Range("A13").Select
Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate ' this finds the first cell
in the colum with
' nothing in it.
ActiveCell.Offset(-1).Activate - this moves me up one, to the last
cell with an entry.
ActiveCell.Offset(1).EntireRow.Insert
ActiveCell.EntireRow.Copy ActiveCell.Offset(1).EntireRow
On Error Resume Next
ActiveCell.Offset(1).EntireRow.SpecialCells(xlCons tants).ClearContents
On Error GoTo 0

I modied it slightly to ignore errors coming from the ClearContents
when it finds no constants on that line.

Here is my problem. While it inserts the row, then keeps only cells
with formulas, not all of the formulas contain the values I expect.
For instance, where a cell copied down contains
=(SUM(B$14:B15)-SUM(D$14:D15)), the cell below it now has
=(SUM(B$14:B16)-SUM(D$14:D16)), which is correct. But for a cell that
contains =Receipt!B5, the cell below it has =Receipt!B7. Why did it
not contain =Receipt!B6? Why did it skip a number?

Very strange.

Thanks for reading.

Carroll Rinehart

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 268
Default Formulas are skipping a row

Hi Carroll

Reading problem on my side!

I do not understand why it does it on your side. I have set up a sheet with
similar formulae, and copied your code into a macro. It works fine on my
side, and does not skip a number.

"Carroll" wrote:

Kassie,

I do want it to change. But I would have expected =Receipt!B5 to have
become =Receipt!B6 when the formula got copied down, not =Receipt!B7.
My question is, why did it skip a number?

Thanks,

Carroll Rinehart


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Formulas are skipping a row

I set up a worksheet as you described, copied your formulas from the email
and put them in the worksheet. I ran your macro and it worked as expected
It copied =receipt!B5 as =Receipt!B6 (Sum formula continued to return
expected results).

If I ran it a second time, I did notice unexpected (well, I expected it),
behavior. It inserted the new row before the row I had just inserted.
This is because there was no formula in columnA when it was copied down so
this cell became blank. Thus the second time it was run, it found the same
empty cell as before and made a premature insertion; so the original new row
remained the last row and the new new row was inserted before it. This may
not be your exact problem, but it could be a similar situation - that
insertions are not occuring where you think they will be.

In any event, the code in isolation should not cause the problem you
describe.
--
Regards,
Tom Ogilvy

"Carroll" wrote in message
oups.com...
Kassie,

I do want it to change. But I would have expected =Receipt!B5 to have
become =Receipt!B6 when the formula got copied down, not =Receipt!B7.
My question is, why did it skip a number?

Thanks,

Carroll Rinehart



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Formulas are skipping a row

Thanks you all for looking at this. While I have gotten it to work
just fine (in isolation), my "live" spreadsheet does not behave so
well. I have looked at this so many ways and have tried many minor
variations. In fact, I have a macro that inserts a line on every sheet
of my live spreadsheet, and some sheets in the spreadsheet have no
problem at all, while others fail to copy it down properly. I have yet
to isolate the problem.

Carroll

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Formulas are skipping a row

If you are inserting lines on all sheets, then the formula may be adjusting
automatically to reflect the new location of the cell it is refering to.

In otherwords, if I put in the formula

=Receipt!B6 in sheet1
then go to Receipt and insert a new row #2 (or any row prior to 6), then the
formula in Sheet1 will adjust to

=Receipt!B7

since you might be working with the last row in each sheet, this is a
distinct possibility.

--
Regards,
Tom Ogilvy



"Carroll" wrote in message
oups.com...
Thanks you all for looking at this. While I have gotten it to work
just fine (in isolation), my "live" spreadsheet does not behave so
well. I have looked at this so many ways and have tried many minor
variations. In fact, I have a macro that inserts a line on every sheet
of my live spreadsheet, and some sheets in the spreadsheet have no
problem at all, while others fail to copy it down properly. I have yet
to isolate the problem.

Carroll





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Formulas are skipping a row

Tom,

That is just so logical, that I would bet money you're right. I'll go
back and check.

Carroll

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Formulas are skipping a row

Yes. I was able to fix it by changing the order in which I added rows
to various sheets. I had to go back and find where all the dependencies
were. I broke it down into 3 groups: do those sheets with absolutely no
dependencies on other sheets first; then do those sheets with
dependencies on the first group, but also fed data to other sheets;
then finally added rows to those sheets that were entirely dependent on
getting their data from other sheets.

So thanks again Tom for setting me straight. I have been banging my
head for quite a few days now.

Carroll

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
reference row on another sheet skipping zeros but not skipping li. Brennan Downes Excel Discussion (Misc queries) 2 April 2nd 23 01:28 PM
Skipping rows Rob Excel Worksheet Functions 1 March 4th 10 04:52 PM
Formulas - Skipping Cells Skipping Cells Excel Discussion (Misc queries) 1 March 24th 08 06:51 PM
Skipping Blanks (Again) F. Lawrence Kulchar Excel Discussion (Misc queries) 3 March 7th 08 10:43 PM
skipping every second cell DDOUBLEU Excel Worksheet Functions 2 November 9th 05 03:00 PM


All times are GMT +1. The time now is 10:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"