Results 1 to 4 of 4

Thread: [RESOLVED] writing formulas from VB6

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    Resolved [RESOLVED] writing formulas from VB6

    Hi
    I am adding formula to an excel worksheet.
    I am using the following code

    VB Code:
    1. Dim wkbSource As Workbook
    2. Dim oXLSheet As Worksheet
    3. Dim j As Integer
    4.  
    5.  
    6. Set wkbSource = Workbooks.Open("C:\test\test.xls")
    7.  
    8. Set oXLSheet = wkbSource.Worksheets("Stat")
    9.  
    10. sKey = InputBox("Enter the name of the Key that u want to add", "KeyManagement")
    11.  
    12. lastRow = oXLSheet.UsedRange.End(xlDown).Row
    13.     j = lastRow + 1
    14.    
    15. oXLSheet.Cells(j, 1).Value = sKey
    16. oXLSheet.Cells(j, 2).Formula = "=SUMPRODUCT(COUNTIF(INDIRECT(" & Chr(34) & "'Sheet1'!L2 : L1000" & Chr(34) & ")," & Chr(34) & "*" & sKey & "*" & Chr(34) & "))"
    17. oXLSheet.Cells(j, 3).Formula= "=SUMPRODUCT(COUNTIF(INDIRECT(" & Chr(34) & "'Sheet2'!L2 : L1000" & Chr(34) & ")," & Chr(34) & "*" & sKey & "*" & Chr(34) & "))"
    18. oXLSheet.Cells(j, 4).Formula= "=SUMPRODUCT(COUNTIF(INDIRECT(" & Chr(34) & "'Sheet3'!L2 : L1000" & Chr(34) & ")," & Chr(34) & "*" & sKey & "*" & Chr(34) & "))"

    let's take an example,let's take sKey="Sports" and j=20 so i want to write a formula into cell E20, the formula is "=sum(B20:D20)"

    I tried writing:

    oXLSheet.cells(j,5).Formula="=sum(cells(j,2):cells(j,4))"but it didn't work
    so how can i do it?
    thanks
    Last edited by RobDog888; Jun 7th, 2006 at 03:48 AM.

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