Can I change this code to be relative to the active cell?

B

BABs

I need to make this code relative to the active cell and not anchored to the
cell number. Is this possible? (K424 = active cell, K420 = offset(-4,0),
R420 = offset(-4,7), and W422 = offset(-2,12) all from the active cell)

With ActiveSheet

' set cell numbers
Dim sR420 As Integer
Dim sK420 As Integer
Dim sK424 As Integer
Dim sW422 As Integer

sR420 = 420
sK420 = 420
sK424 = 424
sW422 = 422

Line1:

'check to see which way we need to adjust the #50 material
If .Range("R420") > 1.9 Then

' set start up value using value from M424
.Range("K" & sK424) = .Range("K424")

' increment value until stopping condition is meet
Do While .Range("W" & sW422) = 0
.Range("K" & sK424) = .Range("K" & sK424) - 0.01
If .Range("K" & sK420) < 2 Then Exit Do
Loop
'End If
Else
' set start up value using value from M424
.Range("K" & sK424) = .Range("K424")

' increment value until stopping condition is meet
Do While .Range("W" & sW422) = 0
.Range("K" & sK424) = .Range("K" & sK424) + 0.01
If .Range("K" & sK420) > 94.9 Then Exit Do
Loop
End If


End With
 
D

Dave Peterson

You can use:

if activecell.offset(-4,0).value > 1.9 then

If you know the .offset()'s (and you do), just change to be adjusted from the
activecell.
 

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