Offset question

P

Patrick C. Simonds

I asked the question below in the public.excel forum. The response I got
indicated that what I asked was not possible without using VBA.

So is there any way using VBA to cause the result of the formula in cell D4
to also be displayed in cell B4. Again I can not have a formula in cell B4.


"I need a formula in cell C4 which will place the value of cell D4 in cell
 
B

Bob Phillips

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "D4" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Offset(0, -2).Value = .Value
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
P

Patrick C. Simonds

It seems what I actually need is:

When cell F4 changes, I need the Value in cell D4 placed in cell B4.
 
B

Bob Phillips

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "F4" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Me.Range("D4").Copy Me.Range("B4")
End If

ws_exit:
Application.EnableEvents = True
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
P

Patrick C. Simonds

Thanks, but that copies the formula in cell D4 to cell B4. I only want the
Value of cell D4 in B4
 
B

Bob Phillips

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "F4" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Me.Range("B4").Value = Me.Range("D4").Value
End If

ws_exit:
Application.EnableEvents = True
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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

Similar Threads

If Condition 4
Non VB Help - 5
+ / - Percentage Variation 3
Supressing a #VALUE! error returned? 3
Add to an Existing formula in a Cell using VBA 1
Months as Column Headings 10
Offset question 1
Excel VBA 1

Top