LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to copy only some rows from range based on condition?

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.
 
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
Summing rows based upon condition Tom Excel Discussion (Misc queries) 2 February 7th 10 06:39 PM
Delete Rows based on condition Vic Excel Discussion (Misc queries) 2 August 18th 09 08:54 PM
Copy and Paste based on Condition EJ Excel Discussion (Misc queries) 1 June 27th 07 11:17 PM
Copy Row based on a condition [email protected] Excel Worksheet Functions 1 April 19th 06 06:05 PM
Create/copy combo boxes in one range if condition is met in a different range LB[_4_] Excel Programming 4 September 30th 05 12:21 AM


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