code modification

  • Thread starter tkraju via OfficeKB.com
  • Start date
T

tkraju via OfficeKB.com

One of code contains these lines:
Dim TargetMonth as Integer
...................
TargetMonth = Month(Range("M1"). Value)
..............
If(Month(Cells(r.Row,3).Value= TargetMonth Then

Value in cell M1 =Apr-09 ,the value is variable.The above code is comparing
only month value of cell M1 value,thus I am getting results of Apr month i.e
(Apr-07,Apr-08,Apr-09).
how to modify the above code ,to compare both month and year of cell M1 value.
 
T

tkraju via OfficeKB.com

Thank you Rick.Dim'ming variables is always a confusing thing for me.Thank
you so much...

Rick Rothstein wrote
Try this...

Dim TargetMonth as Long
Dim TargetYear As Long
..................
TargetMonth = Month(Range("M1"). Value)
TargetYear = Year(Range("M1").Value)
.............
If Month(Cells(r.Row, 3).Value= TargetMonth And _
Year(Cells(r.Row, 3).Value = TargetYear Then

Note: You are saving nothing by Dim'ming variables as Integer... 32-bit
operating systems store Integers in the same space as Longs by default, so
there is no real good reason to limit your numbers (even if you won't reach
the limits of an Integer) by Dim'ming them as Integers.
One of code contains these lines:
Dim TargetMonth as Integer
[quoted text clipped - 10 lines]
how to modify the above code ,to compare both month and year of cell M1
value.
 

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

Top