|
-
Jul 31st, 2006, 11:02 AM
#1
Thread Starter
New Member
Using an If statement in vba for multiple records in a range
Hi all. I am using the following bit of code:
Dim rngCalc As Range
Set rngCalc = Range("AD2:AD" & Cells(Rows.Count, 1).End(xlUp).Row)
rngCalc.Formula = "=(8-K2)"
rngCalc.Value = rngCalc.Value
In this case, the first cell to be replaced is AD2 and it continues for as many rows as I have. What I want to do is use some If statements in conjuction with this, and have these if statements run for each cell (AD2, AD3, AD4, etc)
So in this case, if AD2 = 7 then xxxxxxxxxxxxxx
And so on. Im not sure how to word it. Should it be 'if rngcalc.value = 7'?
I tried that and got a type mismatch. Any help would be appreciated with this, thanks!!!!
-
Jul 31st, 2006, 12:40 PM
#2
Re: Using an If statement in vba for multiple records in a range
If Range("AD2") = 7 then......
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 31st, 2006, 12:45 PM
#3
Thread Starter
New Member
Re: Using an If statement in vba for multiple records in a range
Thank you for the reply.
I tried that, but that only changed AD2. The other cells that = 7 remained at 7. Is there a way to get the code to check for every cell in the range?
-
Jul 31st, 2006, 12:55 PM
#4
Re: Using an If statement in vba for multiple records in a range
Loop it...
VB Code:
For x = 2 to whatever (row count)
If range("AD" & x) = 7 Then
'do something
End If
Next
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 31st, 2006, 01:01 PM
#5
Thread Starter
New Member
Re: Using an If statement in vba for multiple records in a range
Outstanding. Thank you for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|