View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
joel[_69_] joel[_69_] is offline
external usenet poster
 
Posts: 1
Default Selectively Moving Data to a Summary Sheet


I added one IF statnement which fixes both problems. Because the code
didn't find an amount the code thought "Net" was the amount and then
started to search for the next Net" . It turned out the data that was
missing amounts was the 2nd to last section of data so it skipped the
last section on the page.

My code has memory in the fact it rembers what data it found and uses
that information in finding the next piece of information. the code
basically remember that it found the word "Net" or found a dollar
amount. If the code finds a dollar amount it does noting (skipping all
the other dollar amount) until it find the word "Net".

I've been writing code like this for over 30 years starting with
FORTRAN amoung other programming languages.


Enum States
FindNet = 1
FindAmount = 2
End Enum
Sub MakeSummary()

Dim State As States

NewRow = 2
Set Sumsht = Sheets("Summary")



With Sumsht
.Range("A1") = "ID"
.Range("B1") = "Start Date"
.Range("C1") = "End Date"
.Range("D1") = "Net"

End With

For Each OldSht In Sheets
With OldSht
If .Range("A1") = "Ticker" Then
State = FindNet
LastRow = .Range("P" & Rows.Count).End(xlUp).Row
For RowCount = 1 To LastRow
Data = .Range("P" & RowCount)

Select Case State

Case FindNet:
If Data = "Net" Then
State = FindAmount
startDate = .Range("B" & (RowCount + 1))
End If

Case FindAmount:
If Data < "" Then
If Data < "Net" Then
'found first dollar amount
ID = .Range("A" & RowCount)
endDate = .Range("B" & RowCount)
With Sumsht
.Range("A" & NewRow) = ID
.Range("B" & NewRow) = startDate
.Range("C" & NewRow) = endDate
.Range("D" & NewRow) = Data

NewRow = NewRow + 1
End With

State = FindNet
End If
End If
End Select
Next RowCount
End If
End With
Next OldSht
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=146619