PC Review


Reply
Thread Tools Rate Thread

Cal formula upon sorting

 
 
DonLi2006@gmail.com
Guest
Posts: n/a
 
      15th Sep 2007
Hi,

The question I have is a follow-up to my previous question at URL,
http://groups.google.com/group/micro...90e60d9327284e

In case of url problem, the idea and objective is explained here:
Case/Data/Background
C5 = column 5, is a formula that calculate the total minutes (for the
duration between C3 and C4), using Tom from Microsoft's formual of
MOD(c4-c3,1)*24*60.

C1(Date)C2(Task) C3(start) C4(end) C5(cal)
09/11 CF8 17:20 19:00 100
09/12 ink 21:30 23:00 90
9/14 CF8 15:20 18:30 190
New Objective:
Now, if I want to sort by C2 (column 2, Task)
We'll get the following,
C1(Date)C2(Task) C3(start) C4(end) C5(cal)
09/11 CF8 17:20 19:00 100
9/14 CF8 15:20 18:30 190
09/12 ink 21:30 23:00 90
That's helpful but I'd like Excel to automatically insert a row right
below each Task and does automatical subtotalling for the task, the
desired state would look this:
C1(Date)C2(Task) C3(start) C4(end) C5(cal)
9/11 CF8 17:20 19:00 100
9/14 CF8 15:20 18:30 190
290
9/12 ink 21:30 23:00 90
90

How can I do that?

Many thanks.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      15th Sep 2007
I think adding the sub-total uner each section makes it hard to read.
Normally people put the sub total in a new column to the right of the data.
I wrote the code both ways. You choose which you like best

Sub addsubtotal1()
'Put data in column F

RowCount = 2
StartRow = 2
Do While Cells(RowCount, "A") <> ""

If (Cells(RowCount, "B") <> _
Cells(RowCount + 1, "B")) Then

Cells(RowCount, "F").Formula = _
"=Sum(E" & StartRow & ":E" & _
RowCount & ")"
StartRow = RowCount + 1

End If

RowCount = RowCount + 1
Loop
End Sub


Sub addsubtotal2()
'Put data in new row

RowCount = 2
StartRow = 2
Do While Cells(RowCount, "A") <> ""

If (Cells(RowCount, "B") <> _
Cells(RowCount + 1, "B")) Then

Rows(RowCount + 1).Insert
Cells(RowCount + 1, "E").Formula = _
"=Sum(E" & StartRow & ":E" & _
RowCount & ")"

RowCount = RowCount + 2
StartRow = RowCount
Else
RowCount = RowCount + 1
End If

Loop
End Sub


"(E-Mail Removed)" wrote:

> Hi,
>
> The question I have is a follow-up to my previous question at URL,
> http://groups.google.com/group/micro...90e60d9327284e
>
> In case of url problem, the idea and objective is explained here:
> Case/Data/Background
> C5 = column 5, is a formula that calculate the total minutes (for the
> duration between C3 and C4), using Tom from Microsoft's formual of
> MOD(c4-c3,1)*24*60.
>
> C1(Date)C2(Task) C3(start) C4(end) C5(cal)
> 09/11 CF8 17:20 19:00 100
> 09/12 ink 21:30 23:00 90
> 9/14 CF8 15:20 18:30 190
> New Objective:
> Now, if I want to sort by C2 (column 2, Task)
> We'll get the following,
> C1(Date)C2(Task) C3(start) C4(end) C5(cal)
> 09/11 CF8 17:20 19:00 100
> 9/14 CF8 15:20 18:30 190
> 09/12 ink 21:30 23:00 90
> That's helpful but I'd like Excel to automatically insert a row right
> below each Task and does automatical subtotalling for the task, the
> desired state would look this:
> C1(Date)C2(Task) C3(start) C4(end) C5(cal)
> 9/11 CF8 17:20 19:00 100
> 9/14 CF8 15:20 18:30 190
> 290
> 9/12 ink 21:30 23:00 90
> 90
>
> How can I do that?
>
> Many thanks.
>
>

 
Reply With Quote
 
DonLi2006@gmail.com
Guest
Posts: n/a
 
      16th Sep 2007
Thank you, Joel.

I went to the Tools/Macro/Visual Basic Editor and add your following
option A as a module then run the macro, it did not do anything.
Column F is also my calc formula column, and yes, call it Column F is
better, sorry I'm from db world... And my data starts from Row 4...

What did I miss?

>On Sep 15, 4:40 pm, Joel <J...@discussions.microsoft.com> wrote:
> I think adding the sub-total uner each section makes it hard to read.
> Normally people put the sub total in a new column to the right of the data.
> I wrote the code both ways. You choose which you like best
>
> Sub addsubtotal1()
> 'Put data in column F
>
> RowCount = 2
> StartRow = 2
> Do While Cells(RowCount, "A") <> ""
>
> If (Cells(RowCount, "B") <> _
> Cells(RowCount + 1, "B")) Then
>
> Cells(RowCount, "F").Formula = _
> "=Sum(E" & StartRow & ":E" & _
> RowCount & ")"
> StartRow = RowCount + 1
>
> End If
>
> RowCount = RowCount + 1
> Loop
> End Sub
>
> Sub addsubtotal2()
> 'Put data in new row
>
> RowCount = 2
> StartRow = 2
> Do While Cells(RowCount, "A") <> ""
>
> If (Cells(RowCount, "B") <> _
> Cells(RowCount + 1, "B")) Then
>
> Rows(RowCount + 1).Insert
> Cells(RowCount + 1, "E").Formula = _
> "=Sum(E" & StartRow & ":E" & _
> RowCount & ")"
>
> RowCount = RowCount + 2
> StartRow = RowCount
> Else
> RowCount = RowCount + 1
> End If
>
> Loop
> End Sub
>
> OP omitted
>
> - Show quoted text -



 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      16th Sep 2007
There are 3 reason it may not have run
1) It works on the active worksheet. Yoy may have been on another sheet.
2) The code need to be on a module sheet in VBA. Look at the Project window
and add a module page in the workbook that you want to run the code. Module
can be added from the Insert menu or right clicking the workbook in the
project window.
3) Your security mode may be set to high
4) Go to spreadsheet window. Go to tools macro security and change the
security level to medium. SAve the wroklbook. Then close and open the
workbook. When the workbook opens press enable macros.

"(E-Mail Removed)" wrote:

> Thank you, Joel.
>
> I went to the Tools/Macro/Visual Basic Editor and add your following
> option A as a module then run the macro, it did not do anything.
> Column F is also my calc formula column, and yes, call it Column F is
> better, sorry I'm from db world... And my data starts from Row 4...
>
> What did I miss?
>
> >On Sep 15, 4:40 pm, Joel <J...@discussions.microsoft.com> wrote:
> > I think adding the sub-total uner each section makes it hard to read.
> > Normally people put the sub total in a new column to the right of the data.
> > I wrote the code both ways. You choose which you like best
> >
> > Sub addsubtotal1()
> > 'Put data in column F
> >
> > RowCount = 2
> > StartRow = 2
> > Do While Cells(RowCount, "A") <> ""
> >
> > If (Cells(RowCount, "B") <> _
> > Cells(RowCount + 1, "B")) Then
> >
> > Cells(RowCount, "F").Formula = _
> > "=Sum(E" & StartRow & ":E" & _
> > RowCount & ")"
> > StartRow = RowCount + 1
> >
> > End If
> >
> > RowCount = RowCount + 1
> > Loop
> > End Sub
> >
> > Sub addsubtotal2()
> > 'Put data in new row
> >
> > RowCount = 2
> > StartRow = 2
> > Do While Cells(RowCount, "A") <> ""
> >
> > If (Cells(RowCount, "B") <> _
> > Cells(RowCount + 1, "B")) Then
> >
> > Rows(RowCount + 1).Insert
> > Cells(RowCount + 1, "E").Formula = _
> > "=Sum(E" & StartRow & ":E" & _
> > RowCount & ")"
> >
> > RowCount = RowCount + 2
> > StartRow = RowCount
> > Else
> > RowCount = RowCount + 1
> > End If
> >
> > Loop
> > End Sub
> >
> > OP omitted
> >
> > - Show quoted text -

>
>
>

 
Reply With Quote
 
DonLi2006@gmail.com
Guest
Posts: n/a
 
      17th Sep 2007
Hi Joel,

I followed all these steps, still to no avail. btw, my Excel version
is 2000. What else could stand in the way?

Many thanks.

Don

On Sep 16, 12:50 am, Joel <J...@discussions.microsoft.com> wrote:
> There are 3 reason it may not have run
> 1) It works on the active worksheet. Yoy may have been on another sheet.
> 2) The code need to be on a module sheet in VBA. Look at the Project window
> and add a module page in the workbook that you want to run the code. Module
> can be added from the Insert menu or right clicking the workbook in the
> project window.
> 3) Your security mode may be set to high
> 4) Go to spreadsheet window. Go to tools macro security and change the
> security level to medium. SAve the wroklbook. Then close and open the
> workbook. When the workbook opens press enable macros.
>
>
>
> "DonLi2...@gmail.com" wrote:
> > Thank you, Joel.

>
> > I went to the Tools/Macro/Visual Basic Editor and add your following
> > option A as a module then run the macro, it did not do anything.
> > Column F is also my calc formula column, and yes, call it Column F is
> > better, sorry I'm from db world... And my data starts from Row 4...

>
> > What did I miss?


 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      17th Sep 2007
stepping through the code and debugging is the next step.

1) Open the VBA window and click any line inside the macro.
2) pressing F8 will step through the code.
3) to see the values of the variables, right click the variable and then
select add watch. Add rowcount and startrow as two of the watch variables.

I suspect cell A2 is empty. Let me know how far the code runs.

"(E-Mail Removed)" wrote:

> Hi Joel,
>
> I followed all these steps, still to no avail. btw, my Excel version
> is 2000. What else could stand in the way?
>
> Many thanks.
>
> Don
>
> On Sep 16, 12:50 am, Joel <J...@discussions.microsoft.com> wrote:
> > There are 3 reason it may not have run
> > 1) It works on the active worksheet. Yoy may have been on another sheet.
> > 2) The code need to be on a module sheet in VBA. Look at the Project window
> > and add a module page in the workbook that you want to run the code. Module
> > can be added from the Insert menu or right clicking the workbook in the
> > project window.
> > 3) Your security mode may be set to high
> > 4) Go to spreadsheet window. Go to tools macro security and change the
> > security level to medium. SAve the wroklbook. Then close and open the
> > workbook. When the workbook opens press enable macros.
> >
> >
> >
> > "DonLi2...@gmail.com" wrote:
> > > Thank you, Joel.

> >
> > > I went to the Tools/Macro/Visual Basic Editor and add your following
> > > option A as a module then run the macro, it did not do anything.
> > > Column F is also my calc formula column, and yes, call it Column F is
> > > better, sorry I'm from db world... And my data starts from Row 4...

> >
> > > What did I miss?

>
>

 
Reply With Quote
 
DonLi2006@gmail.com
Guest
Posts: n/a
 
      17th Sep 2007
The code runs fine without any error (step through w/ F8 key). And
yes, initially my worksheet has column A blank. So, I copy the data
to a new sheet which reads like
A B C D E F G
1 9/11 CF8 17:20 19:00 100
2 9/13 CF8 10:00 12:00 120
3 9/14 CF8 15:20 18:30 190
4 9/15 CMD 13:00 14:50 110
5 fk bind 21:20 23:00 100
then ran the macro/module against this new sheet only, odd, value in
G3 is now "0:00" and G4 is also "0:00"
I changed the sum to use F column and G for subtotal display.
Probably I wasn't clear enough, F column uses the following formula,
=MOD(D1-C1,1)*24*60

What else can we try, Joel, many thanks.

Don
On Sep 16, 8:20 pm, Joel <J...@discussions.microsoft.com> wrote:
> stepping through the code and debugging is the next step.
>
> 1) Open the VBA window and click any line inside the macro.
> 2) pressing F8 will step through the code.
> 3) to see the values of the variables, right click the variable and then
> select add watch. Add rowcount and startrow as two of the watch variables.
>
> I suspect cell A2 is empty. Let me know how far the code runs.
>
>
>
> "DonLi2...@gmail.com" wrote:
> > Hi Joel,
>> omitted

> - Show quoted text -



 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      17th Sep 2007
Your problem is solved. Just change the format of colum F & G from time to
number. When you add or Sutract time the results is a fraction of a day. 8
hours is 8/24 = .333 days. Like you did in your formula you have to multiply
by 24 * 60 to get minutes. The minutes are no longer a time format after the
conversion, but a number format in minutes.

I think you may need to change this line below to multiply by 24 * 60 like
you did in your fomula.
Cells(RowCount, "F").Formula = _
"=Sum(E" & StartRow & ":E" & _
RowCount & ")"

I think total time sub total is really a subtraction as follows:

Cells(RowCount, "F").Formula = _
"=24*60*(F" & RowCount "-F" & StartRow & ")"

You really should change the format to column D to a date - time format such
as
3/14/01 1:30PM. This will make it easier to calculate the sub total time.

"(E-Mail Removed)" wrote:

> The code runs fine without any error (step through w/ F8 key). And
> yes, initially my worksheet has column A blank. So, I copy the data
> to a new sheet which reads like
> A B C D E F G
> 1 9/11 CF8 17:20 19:00 100
> 2 9/13 CF8 10:00 12:00 120
> 3 9/14 CF8 15:20 18:30 190
> 4 9/15 CMD 13:00 14:50 110
> 5 fk bind 21:20 23:00 100
> then ran the macro/module against this new sheet only, odd, value in
> G3 is now "0:00" and G4 is also "0:00"
> I changed the sum to use F column and G for subtotal display.
> Probably I wasn't clear enough, F column uses the following formula,
> =MOD(D1-C1,1)*24*60
>
> What else can we try, Joel, many thanks.
>
> Don
> On Sep 16, 8:20 pm, Joel <J...@discussions.microsoft.com> wrote:
> > stepping through the code and debugging is the next step.
> >
> > 1) Open the VBA window and click any line inside the macro.
> > 2) pressing F8 will step through the code.
> > 3) to see the values of the variables, right click the variable and then
> > select add watch. Add rowcount and startrow as two of the watch variables.
> >
> > I suspect cell A2 is empty. Let me know how far the code runs.
> >
> >
> >
> > "DonLi2...@gmail.com" wrote:
> > > Hi Joel,
> >> omitted

> > - Show quoted text -

>
>
>

 
Reply With Quote
 
DonLi2006@gmail.com
Guest
Posts: n/a
 
      17th Sep 2007
Works beautiful, Joel, thank you and sorry I was a bit lazy.

Don
On Sep 17, 5:44 am, Joel <J...@discussions.microsoft.com> wrote:
> Your problem is solved. Just change the format of colum F & G from time to
> number. When you add or Sutract time the results is a fraction of a day. 8
> hours is 8/24 = .333 days. Like you did in your formula you have to multiply
> by 24 * 60 to get minutes. The minutes are no longer a time format after the
> conversion, but a number format in minutes.
>
> I think you may need to change this line below to multiply by 24 * 60 like
> you did in your fomula.
> Cells(RowCount, "F").Formula = _
> "=Sum(E" & StartRow & ":E" & _
> RowCount & ")"
>
> I think total time sub total is really a subtraction as follows:
>
> Cells(RowCount, "F").Formula = _
> "=24*60*(F" & RowCount "-F" & StartRow & ")"
>
> You really should change the format to column D to a date - time format such
> as
> 3/14/01 1:30PM. This will make it easier to calculate the sub total time.
>
>
>
> "DonLi2...@gmail.com" wrote:
> omitted
> - Show quoted text -



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting using formula Jan Kronsell Microsoft Excel Discussion 14 7th Feb 2011 02:07 PM
Sorting the cells of a formula causes the formula to not work Jake Microsoft Excel Worksheet Functions 3 31st Jan 2009 04:42 AM
sorting with IF formula Noble Microsoft Excel Worksheet Functions 3 30th Dec 2003 07:30 AM
Sorting by formula results intead of formula text? Jeff Microsoft Excel Misc 1 9th Dec 2003 02:46 AM
Formula Sorting Help srparker Microsoft Excel Misc 0 24th Oct 2003 07:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:02 PM.