ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can I change this code to be relative to the active cell? (https://www.excelbanter.com/excel-programming/433908-can-i-change-code-relative-active-cell.html)

babs

Can I change this code to be relative to the active cell?
 
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

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


All times are GMT +1. The time now is 10:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com