+ Reply to Thread
Results 1 to 6 of 6

Inserting formula into cell/range refering to a range

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2013
    Location
    Houston, US
    MS-Off Ver
    Excel 2007
    Posts
    22

    Inserting formula into cell/range refering to a range

    I'm sure there are many ways to do this and the way I'm doing it is probably the least efficient but anyways I'm getting an error with this. I want to insert an averaging formula into 1200 rows of a sheet that does not include rows with no entries. Here's my code.

    
    For i = 2 To 1201
    
        P_Sht.Cells(i, 2).Formula = "=if(count(C " & i & ":DD " & i & ")>0,Average(C " & i & ":DD " & i & "),"")"
        'Error Here
    Next i
    Is there an easier way of doing this with say R1C1 or something by just being able to paste a range? I want to take the average of C through DD for all these rows.....


    Thanks for any help. Have a nice day.

    -Rob

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Inserting formula into cell/range refering to a range

    You need to double up quotes within VBA, viz:
    P_Sht.Cells(i, 2).Formula = "=if(count(C " & i & ":DD " & i & ")>0,Average(C " & i & ":DD " & i & "),"""")"

  3. #3
    Registered User
    Join Date
    08-16-2013
    Location
    Houston, US
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Inserting formula into cell/range refering to a range

    Still not working with the double quotes

    I also tried where I inserted and & on either side. I get a 1004 error application or object defined error

    P_Sht.Cells(i, 2).Formula = "=if(count(C " & i & ":DD " & i & ")>0,Average(C " & i & ":DD " & i & ")," & "" & ")"

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Inserting formula into cell/range refering to a range

    You have to remove the spaces after C and DD.
    Last edited by StephenR; 08-30-2013 at 01:22 PM.

  5. #5
    Registered User
    Join Date
    08-16-2013
    Location
    Houston, US
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Inserting formula into cell/range refering to a range

    Yeah it is. It works when I just use P_Sht.Cells(i, 2)= i... Is there another way I can do this?

  6. #6
    Registered User
    Join Date
    08-16-2013
    Location
    Houston, US
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Inserting formula into cell/range refering to a range

    Ignore the last message. You were right, It's those spaces.

    Thanks for your help.

+ 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. Max Function with range refering to other cell... Unsuccessful
    By DavidRoger in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-26-2012, 05:42 AM
  2. Refering to a cell in a named range
    By scottintexas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2008, 06:55 PM
  3. Refering to a Dynamic Range in a different Worksheet
    By Fredriksson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2006, 06:21 AM
  4. Change the Range refering to a Name
    By TonTon165 in forum Excel General
    Replies: 2
    Last Post: 06-27-2006, 10:30 AM
  5. help in refering to a range named in a cell
    By jf in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2005, 11:06 AM

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