Selecting a Range inside a range

H

hcova

Hi everybody:
I have the following problem in VBA:
a) I have the column A filled with dates formated as "mm/dd/yy".
b) In the column B, for every date I have a associated a certain integer
number.
I want to select a range in column B that contains only the integers for a
given year.
NOTE: For simplicity I have sorted the column A by date.
How can I do this?
Regards
 
F

Frank Kabel

Hi
what do you want to do with this selection afterwards?

But one way could be (assumption: column A is sorted ascending)
sub foo()
dim rng as range
dim row_start as long
dim row_end as long
dim row_index as long
dim lastrow as long
with activesheet
lastrow = .Cells(Rows.count, "A").End(xlUp).row
For row_index = 1 to lastrow
if Year(.cells(row_index,1))=2004 then
row_start=row_index
exit for
end if
next

For row_index = lastrow to row_start step -1
if Year(.cells(row_index,1))=2004 then
row_end=row_index
exit for
end if
next
set rng=.range("B" & row_start & ":B" & row_end)
end with
rng.select
end sub
 
H

hcova

Hi,
I can not do this because I want to select the range for build a chart per
year.
That´s why I must keep in a VB "range", all data for the same year.
Best regards
Hernan
 
Top