+ Reply to Thread
Results 1 to 2 of 2

Too Long of a formula for a macro?

Hybrid View

  1. #1
    Registered User
    Join Date
    10-24-2012
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    44

    Angry Too Long of a formula for a macro?

    Hello,

    I have a formula that I spent siginficant time trying to develop, but when I try to paste it into my macro I think that it is to long. When I try to paste it is highlighted in red because the ActiveCell.FormulaR1C1 = is not on the same line as the formula. The formula itself fits on one line. Please help me figure out a way to paste it into the macro. I don't want to start from scratch with my formula


    Here is the formula:


    =IF(AND(NOT(D2="All"),NOT(E2="All")),COUNTIFS('TS Data'!E2:E60000,">="&B2,'TS Data'!E2:E60000,"<="&C2,'TS Data'!P2:P60000,D2,'TS Data'!O2:O60000,E2,'TS Data'!K2:K60000,"Yes"),IF(AND(D2="All",NOT(E2="All")),COUNTIFS('TS Data'!E2:E60000,">="&B2,'TS Data'!E2:E60000,"<="&C2,'TS Data'!O2:O60000,E2,'TS Data'!K2:K60000,"Yes"),IF(AND(NOT(D2="All"),E2="All"),COUNTIFS('TS Data'!E2:E60000,">="&B2,'TS Data'!E2:E60000,"<="&C2,'TS Data'!P2:P60000,D2,'TS Data'!K2:K60000,"Yes"),COUNTIFS('TS Data'!E2:E60000,">="&B2,'TS Data'!E2:E60000,"<="&C2,'TS Data'!F2:F60000,"Yes",'TS Data'!K2:K60000,"Yes"))))

    Here is the code

    ActiveCell.FormulaR1C1 =
    "=IF(AND(NOT(R[-3]C[-2]=""All""),NOT(R[-3]C[-1]=""All"")),COUNTIFS('TS Data'!R[-3]C[-1]:R[59995]C[-1],"">=""&R[-3]C[-4],'TS Data'!R[-3]C[-1]:R[59995]C[-1],""<=""&R[-3]C[-3],'TS Data'!R[-3]C[10]:R[59995]C[10],R[-3]C[-2],'TS Data'!R[-3]C[9]:R[59995]C[9],R[-3]C[-1],'TS Data'!R[-3]C[5]:R[59995]C[5],""Yes""),IF(AND(R[-3]C[-2]=""All"",NOT(R[-3]C[-1]=""All"")),COUNTIFS('TS Data'!R[-3]C[-1]:R[59995]C[-1],"">=""&R[-3]C[-4],'TS Data'!R[-3]C[-1]:R[59995]C[-1],""<=""&R[-3]C[-3],'TS Data'!R[-3]C[9]:R[59995]C[9],R[-3]C[-1],'TS Data'!R[-3]C[5]:R[59995]C[5],""Yes""),IF(AND(NOT(R[-3]C[-2]=""All""),R[-3]C[-1]=""All""),COUNTIFS('TS Data'!R[-3]C[-1]:R[59995]C[-1],"">=""&R[-3]C[-4],'TS Data'!R[-3]C[-1]:R[59995]C[-1],""<=""&R[-3]C[-3], 'TS Data'!R[-3]C[10]:R[59995]C[10],R[-3]C[-2],'TS Data'!R[-3]C[5]:R[59995]C[5],""Yes""),COUNTIFS('TS Data'!R[-3]C[-1]:R[59995]C[-1],"">=""&R[-3]C[-4],'TS Data'!R[-3]C[-1]:R[59995]C[-1],""<=""&R[-3]C[-3],'TS Data'!R[-3]C:R[59995]C,""Yes"",'TS Data'!R[-3]C[5]:R[59995]C[5],""Yes""))))"
    Any ideas on what I can do to get it to fit into a macro?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,289

    Re: Too Long of a formula for a macro?

    Sub test()
    ActiveCell.FormulaR1C1 = _
        "=IF(AND(NOT(R[-3]C[-2]=""All""),NOT(R[-3]C[-1]=""All"")),COUNTIFS('TS Data'!R[-3]C[-1]:R[59995]C[-1],"">=""&R[-3]C[-4],'TS Data'!R[-3]C[-1]:R[59995]C[-1],""<=""&R[-3]C[-3],'TS Data'!R[-3]C[10]:R[59995]C[10],R[-3]C[-2],'TS Data'!R[-3]C[9]:R[59995]C[9],R[-3]C[-1],'TS Data'!R[-3]C[5]:R[59995]C[5],""Yes""),IF(AND(R[-3]C[-2]=""All"",NOT(R[-3]C[-1]=""All"")),COUNTIFS('TS Data'!R[-3]C[-1]:R[59995]C[-1],"">=""&R[-3]C[-4],'TS Data'!R[-3]C[-1]:R[59995]C[-1],""<=""&R[-3]C[-3],'TS Data'!R[-3]C[9]:R[59995]C[9],R[-3]C[-1],'TS Data'!R[-3]C[5]:R[59995]C[5],""Yes""),IF(AND(NOT(R[-3]C[-2]=""All""),R[-3]C[-1]=""All""),COUNTIFS('TS Data'!R[-3]C[-1]:R[59995]C[-1],"">=""&R[-3]C[-4],'TS Data'!R[-3]C[-1]:R[59995]C[-1],""<=""&R[-3]C[-3], 'TS Data'!R[-3]C[10]:R[59995]C[10],R[-3]C[-2],'TS Data'!R[-3]C[5]:R[59995]C[5],""Yes""),COUNTIFS('TS Data'!R[-3]C[-1]:R[59995]C[-1],"">=""&R[-3]C[-4],'TS Data'!R[-3]C[-1]:R[59995]C[-1],""<=""&R[-3]C[-3],'TS Data'!R[-3]C:R[59995]C,""Yes"",'TS Data'!R[-3]C[5]:R[59995]C[5],""Yes""))))"
    End Sub

    Note the underscore.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Formula too long to record in Macro, how to convert to VBA?
    By Racheskin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2012, 05:21 PM
  2. Transform a too long Excel formula into a Macro
    By buch84 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2010, 10:52 AM
  3. VBA macro to put Formula in cell - too long?
    By mac8528 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-16-2010, 09:19 AM
  4. Unable to record error, long formula macro problems
    By Jerhansen277 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-25-2008, 06:22 PM
  5. inserting long formula in macro's
    By rjahr01 in forum Excel General
    Replies: 4
    Last Post: 11-06-2006, 01:04 PM

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