+ Reply to Thread
Results 1 to 7 of 7

Error putting excel formula in the cell by vba code

  1. #1
    Registered User
    Join Date
    04-28-2016
    Location
    BD
    MS-Off Ver
    2010
    Posts
    5

    Error putting excel formula in the cell by vba code

    Hi , I have tried several ways to put excel formula into a worksheet cell by vba code, but it is showing errors in each case. The formula is as follows:

    =SUMIFS('Flock 11'!G4:G458,'Flock 11'!A4:A458," >= " &E2,'Flock 11'!A4:A458,"<= " &G2)

    And a little description about the worksheets:

    There are two worksheets, one is "Flock 11", from where the data would be retried and other is "Main" worksheet where the formula is going to be put in.

    I am going to put the above formula in a cell of "Main" worksheet by vba code. That's why I have coded like below:

    Cells(6, i).Value = "=SUMIFS('Flock 11'!G4:G458,'Flock 11'!A4:A458," & "" >= "" & "&E2," & "'Flock 11'!A4:A458," & "" <= "" & "&G2)"

    But type miss match error is showing.

    Any solution please!!!!!

  2. #2
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Error putting excel formula in the cell by vba code

    May be

    Cells(6, i).Value = "=SUMIFS('Flock 11'!G4:G458,'Flock 11'!A4:A458," & "" >= "" & "&E2," & "'Flock 11'!A4:A458," & "" <= "" & "&G2)"

    To this

    Cells(6, i).formula = "=SUMIFS('Flock 11'!G4:G458,'Flock 11'!A4:A458," & "" >= "" & "&E2," & "'Flock 11'!A4:A458," & "" <= "" & "&G2)"
    Happy with my advice? Click on the * reputation button below

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Error putting excel formula in the cell by vba code

    Please Login or Register  to view this content.
    If you are pleased with a member's answer then use the Star icon to rate it.

  4. #4
    Registered User
    Join Date
    04-28-2016
    Location
    BD
    MS-Off Ver
    2010
    Posts
    5

    Re: Error putting excel formula in the cell by vba code

    Thanks buran for your help. I have used your code and it partially worked. Finally the cell holds the formula but could not give any result for that formula. When I manually change the formula to =SUMIFS('Flock 11'!G4:G458,'Flock 11'!A4:A458,">=" &E2,'Flock 11'!A4:A458,"<=" &G2) , I get the result.

  5. #5
    Registered User
    Join Date
    04-28-2016
    Location
    BD
    MS-Off Ver
    2010
    Posts
    5

    Re: Error putting excel formula in the cell by vba code

    Thanks Crooza for your help, but the code didn't work for me.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Error putting excel formula in the cell by vba code

    Perhaps.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    04-28-2016
    Location
    BD
    MS-Off Ver
    2010
    Posts
    5

    Re: Error putting excel formula in the cell by vba code

    Quote Originally Posted by Norie View Post
    Perhaps.
    Please Login or Register  to view this content.
    Thanks Norie, it worked for me.

    Another question, is there any way to get the result of sumifs function without putting the text into the cell? I mean I want to calculate it in the vba procedure and put the result in the cell?

+ 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. [SOLVED] VBA - putting a formula in cells but its got a syntax error please help!! :-)
    By LauraWork in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2013, 08:06 AM
  2. putting an if condition based on text in a cell - runtime error 13: type mismatch
    By rbs123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-29-2013, 04:02 AM
  3. Putting Code To A Button In Excel / VB
    By Rapid in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-16-2013, 12:04 PM
  4. Replies: 10
    Last Post: 12-16-2011, 12:41 PM
  5. Excel 2003 formula: keep currency format when putting text and number in same cell
    By cdstelco in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-16-2011, 05:32 PM
  6. [SOLVED] Excel keeps putting .xls] on my sheets and then I get an error
    By Michelle in forum Excel General
    Replies: 1
    Last Post: 08-02-2006, 07:40 AM
  7. putting formula in cel gives #NAME error
    By Rinze Smit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2005, 03:05 AM
  8. putting value in a cell instead of the formula via vba
    By neowok in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-10-2005, 09:15 AM

Tags for this Thread

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