+ Reply to Thread
Results 1 to 8 of 8

#name!

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    391

    #name!

    Hi all,

    I have the below code to sum a range of valued in the last colum but the return value is #NAME! does anyone know where am I going wrong?

        ESlc = Sheets("Energy Summary").Cells(10, Columns.Count).End(xlToLeft).Column
        
        With Sheets("Energy Summary")
            TotalLC = .Cells(22, Columns.Count).End(xlToLeft).Column
            str2 = .Range(.Cells(10, ESlc), .Cells(21, ESlc)).Address
            
            .Cells(22, TotalLC + 1) = Application.Evaluate("SUM(Energy Summary!str2)")
        End With
    Thanks

  2. #2
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    391

    Re: #name!

    I also tried the below code and I am getting an erorr message saying "Unable to get the Sum poperty of the worksheetfunction class.

    .Cells(22, TotalLC + 1) = Application.WorksheetFunction.Sum(str2)

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,343

    Re: #name!

    Try this.
    Sub tst()
       With Sheets("Energy Summary")
            ESlc = .Cells(10, Columns.Count).End(xlToLeft).Column
            TotalLC = .Cells(22, Columns.Count).End(xlToLeft).Column
            .Cells(22, TotalLC + 1) = Application.Sum(.Range(.Range(.Cells(10, ESlc), .Cells(21, ESlc)).Address))
        End With
    End Sub
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    391

    Re: #name!

    Hi Bakerman,

    Thanks for the reply. It still doe not work. after running the code the cell shows blank but when I click on the cell shown 0 in the formula bar

  5. #5
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    391

    Re: #name!

    Thanks bakerman I was able to fix it but your reply helped a lot to get that fixed.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,343

    Re: #name!

    Just to show you that it does work.
    Attached Files Attached Files

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

    Re: #name!

    Perhaps.
        ESlc = Sheets("Energy Summary").Cells(10, Columns.Count).End(xlToLeft).Column
        
        With Sheets("Energy Summary")
            TotalLC = .Cells(22, Columns.Count).End(xlToLeft).Column
            str2 = .Range(.Cells(10, ESlc), .Cells(21, ESlc)).Address
            
            .Cells(22, TotalLC + 1) = Application.Evaluate("SUM('Energy Summary'!" & str2 & ")")
        End With
    If posting code please use code tags, see here.

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,343

    Re: #name!

    Glad you figured it out. Thanks for the rep points.

+ Reply to Thread

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