Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to get the Active worksheet on change of worksheets [email protected] Excel Programming 2 May 7th 08 02:04 PM
Selecting a range relative to an active cell Steve Trombulak Excel Programming 2 March 26th 08 10:05 PM
Selecting simple range relative to the active cell. jmac68 Excel Programming 2 November 29th 06 12:50 AM
Relative Cell References within VBA code Jandy Excel Discussion (Misc queries) 2 April 21st 05 02:17 AM
Specifying cell reference relative to active cell DeepDarkThought Excel Programming 1 May 6th 04 08:17 PM


All times are GMT +1. The time now is 04:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"