LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
JW JW is offline
external usenet poster
 
Posts: 22
Default Creating Macro to group data

Ah, thank you Jacob.

When you step through each line, if there is a formula attached, will the
result of the formula show as well?

"Jacob Skaria" wrote:

From VBE menu 'Debug''Step Into' (F8) mode iterate through your code and
check where it is going wrong. I have not changed your code. but believe once
you go through this in F8 mode you will get to know where the problem is///

1. The way you get MaxRows it will return the total number of rows. Do you
want all rows to be checked rows with values///


Sub ProcessCells()
Dim Cnt As Long
Dim MaxRows As Long
Dim DailyTotal As Integer

With Worksheets("Beta Test Trade Sheet")
DailyTotal = 0

'MaxRows = Rows.Count - 1
'The above returns the last used row in Column Q
MaxRows = .Cells(Rows.Count, 17).End(xlUp).Row

DateTotal = .Cells(Rows.Count, 20).Value
'The above refers to the last row in T. Is that right?

For DateRng = 2 To DateTotal
For Cnt = 2 To MaxRows
If .Range("Q" & Cnt) = .Range("T" & DateRng) Then
DailyTotal = DailyTotal + .Range("R" & Cnt).Value
End If
Next Cnt
.Cells(DateRng, 21).Value = .Cells(DateRng - 1, 21).Value + DailyTotal
Next DateRng

End With

End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"JW" wrote:

Hello All.

I have a spreadsheet with data from columns A - P. Each Row has a date and
an associated profit/loss amount. Each row does not have a unique date, so
it is possible that row 2 and 4 may have the same date, for example.

I have rewritten in column Q and R the date (column Q) and P/L (column R).
Column T has the unique Date from the earliest to the latest.

Now, here is my question as my VB writing may be missing some
technicalities. I created a nested For/Next loop to examine column T's date
and compare the dates in Column Q and if it matches, add up the p/L. The
result is to print in column U and I am not getting anything to print. Here
is what I have so far...any guidance is appreciated.

Sub ProcessCells()
Dim Cnt As Long
Dim MaxRows As Long
Dim DailyTotal As Integer

DailyTotal = 0
MaxRows = Rows.Count - 1
DateTotal = Cells(Rows.Count, 20).Value
For DateRng = 2 To DateTotal
For Cnt = 2 To MaxRows
If Worksheets("Beta Test Trade Sheet").Cells(Cnt, 17).Value =
Worksheets("Beta Test Trade Sheet").Cells(DateRng, 20).Value Then DailyTotal
= DailyTotal + Worksheets("Beta Test Trade Sheet").Cells(Cnt, 18).Value
Next Cnt
Worksheets("Beta Test Trade Sheet").Cells(DateRng, 21).Value =
Worksheets("Beta Test Trade Sheet").Cells(DateRng - 1, 21).Value + DailyTotal
Next DateRng
End Sub



 
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
How do I group and transpose data - macro help needed. Chris Mitchell Excel Worksheet Functions 4 January 20th 09 02:35 PM
Macro to group data in pivot charts MichaelR Excel Programming 0 June 16th 08 10:37 PM
Creating a preato from a group of data choosen from a pivot chart Dave Excel Discussion (Misc queries) 0 January 7th 08 04:09 PM
Q: Creating a macro to sort and group columns in a sheet according to another sheet [email protected] Excel Programming 0 January 8th 07 09:06 PM
Creating a graph based on a chosen group of data Steve D Charts and Charting in Excel 1 June 20th 06 02:46 PM


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

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"