Selecting a Range inside a range

  • Thread starter Thread starter hcova
  • Start date Start date
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
 
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
 
Why not just use the built in function of count if and
place it into a hidden (or not)colum of your choice.

something like
=COUNTIF($B$1:$B$371,Totals!C$5)

Here I was looking at colum b from row 1 to row 371 to see
if any matched the date that I had in c5 on my Totals
page. But you can just as easly left it at =COUNTIF
(A1:A500,mm/dd/yy)
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top