Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
edb edb is offline
external usenet poster
 
Posts: 1
Default inserting a variable into VB

Hi, I am trying to use a variable (rowNo), which is an integer an
refers to a row number, in this statement:

Range("n5").FormulaArray = "=SUM(J12:J"&rowNo&")"

so that the range is from cell J12 down to JrowNo (what ever rowNo i
it will be greater than 12).

I cannot figure out how to get this to work...
Is this even possible?
Thanks and regards
E

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default inserting a variable into VB

Ed,

That code works perfectly well as long as you add spaces around the &.
However, SUM works on arrays, so you don't need an array formula, this works
just as well

Range("N5").Formula = "=SUM(J12:J" & rowNo & ")"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"edb " wrote in message
...
Hi, I am trying to use a variable (rowNo), which is an integer and
refers to a row number, in this statement:

Range("n5").FormulaArray = "=SUM(J12:J"&rowNo&")"

so that the range is from cell J12 down to JrowNo (what ever rowNo is
it will be greater than 12).

I cannot figure out how to get this to work...
Is this even possible?
Thanks and regards
Ed


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default inserting a variable into VB

Hi Ed

It's an ordinary formula, so

Range("n5").Formula = "=SUM(J12:J" & rowNo & ")"

will do, however notice, that you have to put
spaces around the &'s. If you don't Excel may
"think", that & is the typedeclaration for the
datatype Long, and return an error.

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"edb " skrev i en meddelelse
...
Hi, I am trying to use a variable (rowNo), which is an integer and
refers to a row number, in this statement:

Range("n5").FormulaArray = "=SUM(J12:J"&rowNo&")"

so that the range is from cell J12 down to JrowNo (what ever rowNo is
it will be greater than 12).

I cannot figure out how to get this to work...
Is this even possible?
Thanks and regards
Ed


---
Message posted from http://www.ExcelForum.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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Inserting and retaining an input variable ARGT Excel Discussion (Misc queries) 4 June 26th 08 11:42 PM
Sum cells based on a row variable and seperate column variable CheeseHeadTransplant Excel Worksheet Functions 10 September 23rd 05 06:59 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
reading/inserting variable dates within a macro Dan Wasser Excel Programming 7 January 8th 04 01:21 PM


All times are GMT +1. The time now is 01:36 AM.

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"