Results 1 to 4 of 4

Write SUMIF formula to cell with variables

Threaded View

  1. #1
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Write SUMIF formula to cell with variables

    Hi

    I struggle with syntax and punctuation in writing a formula to a cell using variables.

    I have this code
    Range(ColLetter & LastRow).Formula = "=SUMIF($B6:$B:" & LastRow - 2 & ",""Subtotal""" _
              & "," & ColLetter & "6:" & ColLetter & LastRow - 2 & ") """
    Where
    Dim LastRow As Long
    Dim ColLetter As String
    ColLetter returns E
    LastRow returns 38
    and LastRow -2 would be 36

    This is the result I'm looking for
    Range("E38").Formula = "=sumif($B6:$B36,""Subtotal"",E6:E36)"
    I get run time error 1004 "Application defined or Object defined error". I've been wrestling with this for the last 4 hours and can't seem to get the syntax correct. Your help in showing me where I'm going wrong will be greatly appreciated.

    John
    Last edited by jaslake; 04-07-2010 at 07:50 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

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