+ Reply to Thread
Results 1 to 6 of 6

How can I use variables in =Sum(A1:C1) in a macro

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    How can I use variables in =Sum(A1:C1) in a macro

    the code below calculates the sum of the range B2 to F2 and puts the result into A2.

    Assume I have variables (Integers) x and y which specify columns. X (2) specifies column B and y (6) specifies column F.

    How would the code look using the variables to get the same result as the code below? That is get the result of the sum entered into A2.

    Please Login or Register  to view this content.
    Last edited by dschmitt; 04-06-2010 at 05:23 AM.

  2. #2
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: How can I use variables in =Sum(A1:C1) in a macro

    Please Login or Register  to view this content.
    This seems like the obvious. I would not use x and y but RowNr and ColNr instead. Does the B2:F2 need to be variable as well?

    The you might be looking for something like:
    Please Login or Register  to view this content.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: How can I use variables in =Sum(A1:C1) in a macro

    Please look at the code. Then you know what I want. I want to know the correct coding for that.

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: How can I use variables in =Sum(A1:C1) in a macro

    I think this is what you need:

    Please Login or Register  to view this content.
    Goning to R1C1 style is easier in these cases.

    OR

    Please Login or Register  to view this content.
    OR

    Please Login or Register  to view this content.
    Last edited by rwgrietveld; 04-06-2010 at 04:28 AM.

  5. #5
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: How can I use variables in =Sum(A1:C1) in a macro

    yes, that does it. But there is still one problem left.

    Your solution gives me:
    =SUM($B$2:$F$2)

    What I need is:
    =SUM(B2:F2)

  6. #6
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: How can I use variables in =Sum(A1:C1) in a macro

    Use the last of my previous solutions: R[ ]C[ ] to have a FULL relative solution.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1