#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default adding a formula

I have a macro set up that imports a query from access and adds page breaks
where I need them. (at the end of each group) I do not want them on seperate
spreadsheets. Is there a way to set up a macro that when I run it, it will
insert a blank line at the end of each group and then put a formula to add.
My problem is: the next time I import I may have more rows of information in
one group and maybe less in another. The macro I created will add a blank
row and formula to the same place each time (and this maybe in the middle of
that group). Is it possible to tell excel to find the page break and add a
blank row above it and then put a sum formula in the correct column (the
column is D and E.) (I wanted the formula in column D and E at the end of
each page).
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,089
Default adding a formula

Pam

not sure if this will help. The following routine loops through the data
and, when the value in column A changes, inserts a blank row. It then loops
through again establishing the start and end of each block of data and, when
it finds a blank row, inserts a SUM into columns D and E.

Dim LastRow As Long
Dim StartRow As Long
Dim EndRow As Long

Application.ScreenUpdating = False
LastRow = Range("A65536").End(xlUp).Row
For i = LastRow To 3 Step -1
If Range("A" & i).Value < _
Range("A" & i - 1).Value Then
Range("A" & i).EntireRow.Insert
End If
Next
LastRow = Range("A65536").End(xlUp).Row
For i = 2 To LastRow + 1
If Range("A" & i).Value < "" Then
If StartRow = 0 Then
StartRow = i
End If
Else
EndRow = i - 1
Range("D" & i).Formula = _
"=SUM(D" & StartRow & ":D" & EndRow & ")"
Range("E" & i).Formula = _
"=SUM(E" & StartRow & ":E" & EndRow & ")"
StartRow = 0
End If
Next
Application.ScreenUpdating = True


It doesn't take any account of Page Breaks. You might be able to modify it
to look for Page Breaks instead but I haven't had time to try that. Not
sure if you need to do anything if the Page Break is at the start of a block
anyway. If you insert a lot of additional blank lines you might need to
adjust your Page Breaks.

Regards

Trevor


"Pam Coleman" wrote in message
...
I have a macro set up that imports a query from access and adds page
breaks
where I need them. (at the end of each group) I do not want them on
seperate
spreadsheets. Is there a way to set up a macro that when I run it, it
will
insert a blank line at the end of each group and then put a formula to
add.
My problem is: the next time I import I may have more rows of information
in
one group and maybe less in another. The macro I created will add a
blank
row and formula to the same place each time (and this maybe in the middle
of
that group). Is it possible to tell excel to find the page break and add
a
blank row above it and then put a sum formula in the correct column (the
column is D and E.) (I wanted the formula in column D and E at the end of
each page).



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
My formula cell has stopped adding the preceding cells. Miriam Excel Worksheet Functions 1 June 2nd 06 03:35 PM
Excel formula to calculate % gain when adding cash equity to accou Anita Excel Worksheet Functions 0 April 29th 06 04:19 PM
Adding something to a complicated formula Roz Excel Discussion (Misc queries) 6 December 20th 05 09:00 PM
Match then lookup Tenacity Excel Worksheet Functions 9 December 3rd 05 05:30 AM
adding a formula in a cell but when cell = 0 cell is blank Mike T Excel Worksheet Functions 5 May 31st 05 01:08 AM


All times are GMT +1. The time now is 09:36 AM.

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

About Us

"It's about Microsoft Excel"