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

Hi
I have what I thought was a simple problem, but it isn't. Within a VBA
subroutine I choose a cell address, say $B$10 and wish to place a formula
in it - say "=$A10-$A$9". (Not manually, but within VBA). can anyone help??

thanks in advance.

Brian Wild


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default Entering Formulas in VBA

from Immediate window:
activesheet.range("$B$10").formula = "=$A$10-$A$9"
HTH

"Brian Wild" wrote in message
...
Hi
I have what I thought was a simple problem, but it isn't. Within a VBA
subroutine I choose a cell address, say $B$10 and wish to place a formula
in it - say "=$A10-$A$9". (Not manually, but within VBA). can anyone
help??

thanks in advance.

Brian Wild



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Entering Formulas in VBA


Thanks for the remarkably quick response. However, it indicates that I
have not expressed the problem clearly enough. I don't know in advance
that the target cell will be (e.g.) $B$10 - but once it has been
determined the desired formula to be entered is calculated using the
details of its address. I can set up a string variable to represent the
formula, but can't see how to get VBA to accept this as a formula in the
chosen cell. I could of course enter the formula manually via a dialog
box - but there are several such cases to be handled and it would become
laborious.

Brian Wild

*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Entering Formulas in VBA

Brian
If the formula is suppose to work on cells that are always in a "relative"
position to the target cell, you can use the .formulaR1C1 function.
ie ActiveCell.FormulaR1C1 = "=R[-2]C[-1]+R[-1]C[-1]"


"Brian Wild" wrote:


Thanks for the remarkably quick response. However, it indicates that I
have not expressed the problem clearly enough. I don't know in advance
that the target cell will be (e.g.) $B$10 - but once it has been
determined the desired formula to be entered is calculated using the
details of its address. I can set up a string variable to represent the
formula, but can't see how to get VBA to accept this as a formula in the
chosen cell. I could of course enter the formula manually via a dialog
box - but there are several such cases to be handled and it would become
laborious.

Brian Wild

*** Sent via Developersdex http://www.developersdex.com ***

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default Entering Formulas in VBA

Maybe I've missed the point, but how bout this?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Target.Formula = "=$A$10-$A$9"
Cancel = True
End Sub


"Brian Wild" wrote in message
...

Thanks for the remarkably quick response. However, it indicates that I
have not expressed the problem clearly enough. I don't know in advance
that the target cell will be (e.g.) $B$10 - but once it has been
determined the desired formula to be entered is calculated using the
details of its address. I can set up a string variable to represent the
formula, but can't see how to get VBA to accept this as a formula in the
chosen cell. I could of course enter the formula manually via a dialog
box - but there are several such cases to be handled and it would become
laborious.

Brian Wild

*** Sent via Developersdex http://www.developersdex.com ***





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
Entering Formulas Justme Excel Worksheet Functions 6 August 14th 08 10:05 AM
Entering Formulas Rey Excel Discussion (Misc queries) 5 August 8th 07 08:40 PM
Entering Formulas Nickydad Excel Worksheet Functions 2 September 20th 06 02:12 AM
Entering formulas Nickydad Excel Worksheet Functions 1 September 20th 06 12:11 AM
entering formulas Tara Martin Excel Worksheet Functions 1 April 6th 06 07:33 PM


All times are GMT +1. The time now is 12:22 PM.

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

About Us

"It's about Microsoft Excel"