Results 1 to 2 of 2

Thread: [RESOLVED] Create excel formula referring to "column numbers"

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Resolved [RESOLVED] Create excel formula referring to "column numbers"

    I am trying to use Visual Basic 6 to create a formula in a cell, but the formula refers to cells that are stored in variables as a column number and a row number.
    For example, let's say I wanted to create a formula
    =SUM(C6: D12) [There should be no space between the colon and the D, but it was creating a smiley where it shouldn't have!]
    The problem is: my program only knows these cells by 4 integers: Row 6(intRowOne), Column 3(intColOne), Row 12(intRowTwo), and Column 4(intColTwo). Is there any way I can create this formula only knowing the names of the variables?
    I have tried:
    Code:
    oXLSheet.Cells(49,3).Formula = "=SUM(" & oXLSheet.Cells(intRowOne, intColOne) & ":" & oXLSheet.Cells(intRowTwo, intColTwo) & ")"
    I have also tried:
    Code:
    oXLSheet.Cells(49,3).Formula = "=SUM(" & oXLSheet.Range(oXLSheet.Cells(intRowOne, intColOne), oXLSheet.Cells(intRowTwo, intColTwo)) & ")"
    But got no luck. Any other ideas? Thanks.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    75

    Resolved Re: [RESOLVED] Create excel formula referring to "column numbers"

    I just found the solution by adding "Address" to each cell:
    Code:
    oXLSheet.Cells(49,3).Formula = "=SUM(" & oXLSheet.Cells(intRowOne, intColOne).Address & ":" & oXLSheet.Cells(intRowTwo, intColTwo).Address & ")"
    Although using this method, when I looked in Excel, it said "=SUM($C$6:$D$12)" and I wasn't expecting the dollars signs, but it still seems to work fine.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width