Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Code to get the Active worksheet on change of worksheets | Excel Programming | |||
Selecting a range relative to an active cell | Excel Programming | |||
Selecting simple range relative to the active cell. | Excel Programming | |||
Relative Cell References within VBA code | Excel Discussion (Misc queries) | |||
Specifying cell reference relative to active cell | Excel Programming |