View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Can I change this code to be relative to the active cell?

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.

BABs wrote:

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


--

Dave Peterson