If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > insert formula with vb

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-22-04, 05:38
NaugGc NaugGc is offline
Registered User
 
Join Date: Sep 2004
Posts: 16
insert formula with vb

Hello, ppl

I have 2 sets of columns - one with values and one with formulas that use values. Formulas are meant to change depending on a certain condition so I want to insert them with VB macro.

For example I want cells in column E to equal cell B- cellA from the same row.
So, questions:
1)how do I explain to vb that I want this formula applied to whole range (i.e. how do I define row number)
2) How do I define column name - in my prog I use column numbers - is there any way to translate column number into column name (1=A, 2=B)
Reply With Quote
  #2 (permalink)  
Old 09-22-04, 07:49
NaugGc NaugGc is offline
Registered User
 
Join Date: Sep 2004
Posts: 16
in case someone else has similar problem the solution is
Selection.FormulaR1C1=R[-5]-R[-6]
where number in brackets is disstance to left of cell in question measured in columns
Reply With Quote
  #3 (permalink)  
Old 10-02-04, 11:32
Smitty Smitty is offline
Registered User
 
Join Date: Dec 2003
Location: San Diego, CA
Posts: 153
Welcome to the Board!

The quickest way to get the correct syntax for almost any formula in VBA is to record a macro, F2 on the cell containing the formula, then enter and stop recording.

That will give you the R1C1 rference style that you posted. You can use actual cell references as well, and you can also look into the helpfile for Application.WorksheetFunction.

Hope that helps,

Smitty
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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