Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Formula Syntax

Excel 2000
I'm new to using VBA with Excel.
What I am trying to do is change the formula in a cell based on which cell
is active (has focus) Such As:


Private Sub Worksheet_Selection Change( byval target as range)
If Target.Address = "$A$1" Then
Range("E1") = (B1+C1)/D1
Elseif Target.Address = "$A$2" Then
Range("E1") = (B2+C2)/D2
End If

The part I'm having problem with is the syntax for the formula:
Range("E1") = (B1+C1)/D1

Any help appreciated!
Dale

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA Formula Syntax

Dale,


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "$A$1" Then
Range("E1").Formula = "=(B1+C1)/D1"
ElseIf Target.Address = "$A$2" Then
Range("E1").Formula = "=(B2+C2)/D2"
End If

End Sub

--
Regards,
Soo Cheon Jheong
_ _
^ąŻ^
--


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA Formula Syntax

Hi Dale,

Try this

Private Sub Worksheet_Selection Change( byval target as range)
If Target.Address = "$A$1" Then
Range("E1").Formula = "=(B1+C1)/D1"
Elseif Target.Address = "$A$2" Then
Range("E1").Formula = "=(B2+C2)/D2"
End If


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dale" wrote in message
...
Excel 2000
I'm new to using VBA with Excel.
What I am trying to do is change the formula in a cell based on which cell
is active (has focus) Such As:


Private Sub Worksheet_Selection Change( byval target as range)
If Target.Address = "$A$1" Then
Range("E1") = (B1+C1)/D1
Elseif Target.Address = "$A$2" Then
Range("E1") = (B2+C2)/D2
End If

The part I'm having problem with is the syntax for the formula:
Range("E1") = (B1+C1)/D1

Any help appreciated!
Dale



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default VBA Formula Syntax

Hi Dale

You're pretty close:

Range("E1").Formula = "=(B1+C1)/D1"

HTH. Best wishes Harald

"Dale" skrev i melding
...
Excel 2000
I'm new to using VBA with Excel.
What I am trying to do is change the formula in a cell based on which cell
is active (has focus) Such As:


Private Sub Worksheet_Selection Change( byval target as range)
If Target.Address = "$A$1" Then
Range("E1") = (B1+C1)/D1
Elseif Target.Address = "$A$2" Then
Range("E1") = (B2+C2)/D2
End If

The part I'm having problem with is the syntax for the formula:
Range("E1") = (B1+C1)/D1

Any help appreciated!
Dale



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default VBA Formula Syntax

try

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 1 Then Exit Sub
With Target
Range("e1") = (.Offset(0, 1) + .Offset(0, 2)) / .Offset(0, 3)
End With
End Sub
--
Don Guillett
SalesAid Software

"Dale" wrote in message
...
Excel 2000
I'm new to using VBA with Excel.
What I am trying to do is change the formula in a cell based on which cell
is active (has focus) Such As:


Private Sub Worksheet_Selection Change( byval target as range)
If Target.Address = "$A$1" Then
Range("E1") = (B1+C1)/D1
Elseif Target.Address = "$A$2" Then
Range("E1") = (B2+C2)/D2
End If

The part I'm having problem with is the syntax for the formula:
Range("E1") = (B1+C1)/D1

Any help appreciated!
Dale





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default VBA Formula Syntax

Just another idea. Not sure if you want to insert a formula, of just the
value.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 1 Then
Target.Offset(0, 4).FormulaR1C1 = "=(RC[-3]+RC[-2])/RC[-1]"
End If
End Sub

--
Dana DeLouis
Win XP & Office 2003


"Dale" wrote in message
...
Excel 2000
I'm new to using VBA with Excel.
What I am trying to do is change the formula in a cell based on which cell
is active (has focus) Such As:


Private Sub Worksheet_Selection Change( byval target as range)
If Target.Address = "$A$1" Then
Range("E1") = (B1+C1)/D1
Elseif Target.Address = "$A$2" Then
Range("E1") = (B2+C2)/D2
End If

The part I'm having problem with is the syntax for the formula:
Range("E1") = (B1+C1)/D1

Any help appreciated!
Dale



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
Formula syntax Dale G[_2_] Excel Discussion (Misc queries) 9 January 24th 10 06:08 PM
formula syntax. Babs Excel Discussion (Misc queries) 3 February 23rd 08 10:56 AM
Syntax of formula [email protected] Excel Worksheet Functions 2 December 15th 06 10:43 AM
Formula Syntax John Johns Excel Worksheet Functions 1 February 18th 06 12:18 PM
Formula syntax {;;;} Simplefi Excel Worksheet Functions 2 June 20th 05 05:48 PM


All times are GMT +1. The time now is 08:57 PM.

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"