J
joeu2004
I am giving myself a crash course in VBA programming using
Walkenbach's book. Hopefully I can figure this out for myself
in due time. But as a double-check and perhaps for expediency
(learn by example), I would appropriate it if someone would
show me a VBA sub (executed using alt-F8) to do the following.
I have a worksheet with 10200 daily stock prices (date, open,
high, low, close). I want to build worksheet with the last stock
prices of each month. (Note: I have good reasons for not
simply getting this from Yahoo or other online service.)
The pseudocode for the VBA sub that I have in mind is (better
ideas are welcomed):
' data is ordered from most recent to oldest date
' skip 1st month (might be partial)
lastMonth = month(first cell in selected range)
for each cell in selected range
if month(cell) <> lastMonth then
copy 5 contiguous columns (same row) to the right
to new row in another (specified) worksheet
lastMonth = month(cell)
end if
next cell
Note: Can "selected range" be just the date column, or must
it encompass all 5 columns in the 10200 rows? Even if can be
just the date column, is there any advantage (in execution
time or ease of programming) to encompassing all 5 columns?
PS: If you are kind enough to post a prototype VBA, there is
no need or expectation to test it. I can do that. I am just
hoping for a leg-up on relevant nuances of the VBA language.
TIA.
Walkenbach's book. Hopefully I can figure this out for myself
in due time. But as a double-check and perhaps for expediency
(learn by example), I would appropriate it if someone would
show me a VBA sub (executed using alt-F8) to do the following.
I have a worksheet with 10200 daily stock prices (date, open,
high, low, close). I want to build worksheet with the last stock
prices of each month. (Note: I have good reasons for not
simply getting this from Yahoo or other online service.)
The pseudocode for the VBA sub that I have in mind is (better
ideas are welcomed):
' data is ordered from most recent to oldest date
' skip 1st month (might be partial)
lastMonth = month(first cell in selected range)
for each cell in selected range
if month(cell) <> lastMonth then
copy 5 contiguous columns (same row) to the right
to new row in another (specified) worksheet
lastMonth = month(cell)
end if
next cell
Note: Can "selected range" be just the date column, or must
it encompass all 5 columns in the 10200 rows? Even if can be
just the date column, is there any advantage (in execution
time or ease of programming) to encompassing all 5 columns?
PS: If you are kind enough to post a prototype VBA, there is
no need or expectation to test it. I can do that. I am just
hoping for a leg-up on relevant nuances of the VBA language.
TIA.