Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Use variable in macro coding

I want to give sum command i.e. =SUM(H1:H10) and my variable for
mFrow = 1 and mLrow = 10 how can i use variable in function
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 703
Default Use variable in macro coding


MyFormula="Sum("H" & mFrow & ":H" & mLrow & ")"

---
Per

On 17 Jul., 07:42, bmurlidhar wrote:
I want to give sum command *i.e. =SUM(H1:H10) and my variable for
mFrow = 1 and mLrow = 10 how can i use variable in function


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Use variable in macro coding

Not sure exactly what you mean by "give the sum command"...

If you want to sum a range, then one way:

Dim dSum As Double
Dim mFrow As Long
Dim mLrow As Long

mFrow = 1
mLrow = 10

dSum = Application.Sum(Range(Cells(mFrow, 8), Cells(mLrow, 8)))


If you want to put a formula in a cell, then one way:

Dim mFrow As Long
Dim mLrow As Long

mFrow = 1
mLrow = 10

Cells(1, 1).Formula = "=SUM(H" & mFrow & ":H" & mLrow & ")"




In article
,
bmurlidhar wrote:

I want to give sum command i.e. =SUM(H1:H10) and my variable for
mFrow = 1 and mLrow = 10 how can i use variable in function

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Use variable in macro coding

If your variables are stored in cells, you can do something like the
following:
1. Assuming the value of mFrow is stored in A1 and the value of mLrow is
stored in A2.
2. In cell A3, write down the following:
=TEXT("H" & A1 & ":H" & A2, "")
3. In cell A4, you can get your sum with the following formula:
=SUM(INDIRECT(A3))

Basically, in cell A3, we are building up the expression "H1:H10" and in
cell A4, we are using the string in A3 to build the range using the
INDIRECT() function.

- Chirag

Shortcut Manager - Assign keyboard shortcuts to Excel menu items and
macros.
http://officeone.mvps.org/xlsctmgr/xlsctmgr.html

"bmurlidhar" wrote in message
...
I want to give sum command i.e. =SUM(H1:H10) and my variable for
mFrow = 1 and mLrow = 10 how can i use variable in function


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
Help on macro coding for URL Eric Excel Worksheet Functions 2 March 15th 08 02:02 PM
Please help on coding the macro. Eric Excel Worksheet Functions 0 March 11th 08 03:11 PM
HELP - coding on Macro! Eric Excel Worksheet Functions 3 February 21st 08 12:26 AM
Including a third variable in a point diagram by color-coding Celia Excel Discussion (Misc queries) 1 January 29th 08 04:47 PM
coding macro Boss Excel Discussion (Misc queries) 0 November 13th 07 12:17 PM


All times are GMT +1. The time now is 06:17 AM.

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"