Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum

Tough to describe, please take a look at the test sheet.
Similar to recent post but the sheet format is much different.

If you will click the "Class row" row button then enter a 1 in the box, you will see a row inserted at the change of each class value. I have a code line that simulates adding the formulas in the data field, it puts "XX" in the first group of four columns.

Frankly I am not sure how I made that work but it is merely a start.

Each XX will need to be a formula (or the result of a formula) to add the cells above it to up to the next class break.

And to go on across the sheet to the end of the data field.

Skip a column every four columns and four more formulas. I cannot even come up with the formulas nor how to traverse the newly inserted rows with the formulas.

The formula cells need to be formatted, Bold, Top & Bottom Border, and interior colorindex 17.

The "Reset C" button puts the data back as was before rows were inserted.

https://www.dropbox.com/s/1aiz6hstvg...heet.xlsm?dl=0

Thanks,
Howard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Mid column sum formulas with varied ranges to sum

Hi Howard,

Am Fri, 5 Dec 2014 17:12:46 -0800 (PST) schrieb L. Howard:

If you will click the "Class row" row button then enter a 1 in the box, you will see a row inserted at the change of each class value. I have a code line that simulates adding the formulas in the data field, it puts "XX" in the first group of four columns.


Each XX will need to be a formula (or the result of a formula) to add the cells above it to up to the next class break.


please explain a little more. I understand to insert a row on class end
to sum the class items. But what should happen if you insert more than
one row? Then you make a sum out of the class items and the sum in the
row above. The second sum is twice the first sum. The third sum is twice
the second sum and so on. What is the reason behind?


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum

please explain a little more. I understand to insert a row on class end
to sum the class items. But what should happen if you insert more than
one row? Then you make a sum out of the class items and the sum in the
row above. The second sum is twice the first sum. The third sum is twice
the second sum and so on. What is the reason behind?


Regards
Claus B.



Hi Claus, thanks for taking a look

I changed the link to show an example of how the finished product should look.

I only did two lines of formulas, but all the newly inserted rows would look like the two blue filled lines. Row 25 and row 33 would look the same as rows 14 and 17.

No total in column B or C. (column C is for test purposes only and does not exist on real sheet)

Later the data will change and the that need totals will occur in different rows.

I presume when the data is changed the formatting will revert to "None", then in the new data set the code will inserted new rows and totals and format them.

Howard
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum



<Later the data will change and the that need totals will occur in different rows.

Should say:

Later the data will change and then the totals will occur in different rows.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum

Another edit.

There would also be a total row at the bottom of the data, in row 37, it would total the Class 44 data in this example.

Howard


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Mid column sum formulas with varied ranges to sum

Hi again,

Am Sat, 6 Dec 2014 03:35:07 -0800 (PST) schrieb L. Howard:

There would also be a total row at the bottom of the data, in row 37, it would total the Class 44 data in this example.


I have two additional questions:

1. Don't you need in $ column the sumproduct of units and price?

2. Is each 5th column empty? If so, it is easier to write formula and
format through AB:CK and delete it in each 5th column instead of looping
through the cells


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum


I have two additional questions:

1. Don't you need in $ column the sumproduct of units and price?

2. Is each 5th column empty? If so, it is easier to write formula and
format through AB:CK and delete it in each 5th column instead of looping
through the cells


Regards
Claus B.



1. Don't you need in $ column the sumproduct of units and price?

Hmm, not sure. I don't know what to say on that.
What would be in the $ column if it were so?



2. Is each 5th column empty?

Yes this is true. That is how I entered the sum formulas in the two example rows. I pulled the first formula across, and then formatted all the cells while they were selected and deleted the unused 5th column cells. A code version of that makes good sense.

I did neglect to format the $ columns cell to currency.

Howard

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum

...deleted the unused 5th column cells.

Actually just deleted the formatting, sorry.

H
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Mid column sum formulas with varied ranges to sum

Hi Howard,

Am Sat, 6 Dec 2014 05:26:30 -0800 (PST) schrieb L. Howard:

...deleted the unused 5th column cells.

Actually just deleted the formatting, sorry.


have a look:
https://onedrive.live.com/?cid=9378A...121822A3%21326
for "Tracker Sheet2"

Run macro "InsertRows". That it works correctly I changed the formulas
into values.


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum

On Saturday, December 6, 2014 7:55:13 AM UTC-8, Claus Busch wrote:
Hi Howard,

Am Sat, 6 Dec 2014 05:26:30 -0800 (PST) schrieb L. Howard:

...deleted the unused 5th column cells.

Actually just deleted the formatting, sorry.


have a look:
https://onedrive.live.com/?cid=9378A...121822A3%21326
for "Tracker Sheet2"

Run macro "InsertRows". That it works correctly I changed the formulas
into values.



Well that is quite remarkable!!

The sumproduct make sense to me now...DUH on me!

I would think both SumProduct and Values would be the proper method to use. That is unconfirmed to me at present.

I will save a workbook with the formulas and if you would change the linked version to values, that should cover all the bases.

Thanks tons, and I will be sure to have your name on the code.

Howard

P.S.
I guess the only other thing I would ask is, I have this bale of straw, would you please write some code that will turn it into gold.



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Mid column sum formulas with varied ranges to sum

Hi Howard,

Am Sat, 6 Dec 2014 09:04:44 -0800 (PST) schrieb L. Howard:

I would think both SumProduct and Values would be the proper method to use. That is unconfirmed to me at present.


if the user inserts rows with values you better work with formula. The
formula modifies automatically.
Do you have the newest version of the workbook? I had a little error in
the first one I uploaded.


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum

On Saturday, December 6, 2014 9:10:13 AM UTC-8, Claus Busch wrote:
Hi Howard,

Am Sat, 6 Dec 2014 09:04:44 -0800 (PST) schrieb L. Howard:

I would think both SumProduct and Values would be the proper method to use. That is unconfirmed to me at present.


if the user inserts rows with values you better work with formula. The
formula modifies automatically.
Do you have the newest version of the workbook? I had a little error in
the first one I uploaded.


I just now downloaded a version and I noticed it ran quite a bit faster than a previous one.

I assume I have the latest.

Also, to change to values this seems to do it.

With .Cells(i, n)
.Formula = "=SUM(" & myRng1 & ")": .Value = .Value

And the same for the Sumproduct line.

So going from formulas to values or back looks like something I can do if needed.

Howard
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Mid column sum formulas with varied ranges to sum

Hi Howard,

Am Sat, 6 Dec 2014 09:54:12 -0800 (PST) schrieb L. Howard:

.Formula = "=SUM(" & myRng1 & ")": .Value = .Value


I would prefer formulas. But if the user want values try in in one step:

Sub InsertRows()
Dim LRow As Long, Start As Long, i As Long
Dim wsh As Worksheet
Dim n As Long, lRowsInsert As Long, CountUniques As Long
Dim myRng1 As String, myrng2 As String

Const myRow As Long = 10
Const myCol As Long = 3

lRowsInsert = Application.InputBox("Enter number of rows to insert", _
"Insert rows", Type:=1)

If lRowsInsert = 0 Or lRowsInsert = False Then Exit Sub

If lRowsInsert < 1 Then
MsgBox "Error - please enter a value equal to or greater than 1"
Exit Sub
End If

MsgBox "This code will insert " & lRowsInsert & " row/s" & vbCr & _
"wherever CLASS values change in" & vbCr & "column " _
& myCol & " starting from row number " & myRow

Application.ScreenUpdating = False

Set wsh = Sheets("5. Tracker")
With wsh
LRow = .Cells(Rows.Count, myCol).End(xlUp).Row
CountUniques = Evaluate("=Countif(" & .Range(.Cells(myRow, myCol),
..Cells(LRow, myCol)).Address & _
"," & .Range(.Cells(myRow, myCol), .Cells(LRow, myCol)).Address &
")")

For i = LRow To myRow + 1 Step -1
If .Cells(i - 1, myCol) < .Cells(i, myCol) And _
Len(.Cells(i - 1, myCol)) 0 Then
Rows(i).Resize(rowsize:=lRowsInsert).Insert
i = i - lRowsInsert
End If
Next

Start = myRow
LRow = .Cells(Rows.Count, myCol).End(xlUp).Row
For i = Start To LRow + lRowsInsert
If Len(.Cells(i, 28)) = 0 And Not .Cells(i - 1, 28).HasFormula
Then
For n = 28 To 89
If n Mod 5 = 3 Or n Mod 5 = 0 Then
myRng1 = .Range(.Cells(Start, n), .Cells(i - 1,
n)).Address
With .Cells(i, n)
.Formula = "=SUM(" & myRng1 & ")"
.Interior.ColorIndex = 17
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlMedium
End With
ElseIf n Mod 5 = 4 Or n Mod 5 = 1 Then
myRng1 = .Range(.Cells(Start, n), .Cells(i - 1,
n)).Address
myrng2 = .Range(.Cells(Start, n - 1), .Cells(i - 1, n -
1)).Address
With .Cells(i, n)
.Formula = "=SUMPRODUCT(" & myRng1 & "," & myrng2 &
")"
.Interior.ColorIndex = 17
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlMedium
.NumberFormat = "[$$-409]#,##0.00"
End With
End If
Next
Start = i + lRowsInsert
i = i + lRowsInsert
End If
Next
With .Range(.Cells(myRow, "AB"), .Cells(LRow,
"CK")).SpecialCells(xlCellTypeFormulas)
.Value = .Value
End With
End With

Application.ScreenUpdating = True
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum

Great. I'll keep in on hand and thanks again.

Howard

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Mid column sum formulas with varied ranges to sum

Hi Howard,

Am Sat, 6 Dec 2014 10:47:21 -0800 (PST) schrieb L. Howard:

Great. I'll keep in on hand and thanks again.


I made some changes to make the code faster. Please look again in
OneDrive.


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional


  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum

Hi Claus,

Indeed, it is faster on the 800+ rows I tested, about half the time of the others.

Can there be a FORMULA version of the faster code?

Howard
  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Mid column sum formulas with varied ranges to sum

Hi Howard,

Am Sat, 6 Dec 2014 11:34:35 -0800 (PST) schrieb L. Howard:


Can there be a FORMULA version of the faster code?


I have comments into the code. Comment out the 3 rows that change the
formulas to values.
If the user needs values he can change it back.


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Mid column sum formulas with varied ranges to sum

On Saturday, December 6, 2014 11:38:41 AM UTC-8, Claus Busch wrote:
Hi Howard,

Am Sat, 6 Dec 2014 11:34:35 -0800 (PST) schrieb L. Howard:


Can there be a FORMULA version of the faster code?


I have comments into the code. Comment out the 3 rows that change the
formulas to values.
If the user needs values he can change it back.



Woops, sorry. Noticed the comments but did not read them. My bad and thanks again.

Howard
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
Varied product list Montana Excel Discussion (Misc queries) 4 April 1st 08 12:48 AM
Varied Pay rates Peter Welly Excel Discussion (Misc queries) 7 March 22nd 08 03:41 AM
Subtotaling a Varied length Spreadsheet Theo Degr Excel Programming 1 July 3rd 07 06:12 PM
formulas involving ranges Brenda463 Excel Worksheet Functions 2 July 21st 06 10:41 PM
Ranges in array formulas cottage6 Excel Programming 3 July 20th 05 06:09 AM


All times are GMT +1. The time now is 08:08 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"