Solved

vba code

Posted on 2012-03-13
4
171 Views
Last Modified: 2012-03-14
Why will this not work?  AHHH

Range("d" & Rows.Count).End(xlUp).Formula = "=sum(d2:"&Range("d" & Rows.Count).End(xlUp).Range")"
0
Comment
Question by:BigWill5112
  • 3
4 Comments
 
LVL 10

Accepted Solution

by:
Anthony Berenguel earned 500 total points
ID: 37718308
the following has not been tested but try...
Range("d" & Rows.Count).End(xlUp).Formula = "=sum(d2:" & Range("d" & Rows.Count).End(xlUp).Range & ")"

Open in new window

0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 37718317
BigWill, I took a second look at your code and I'm having trouble understanding what you're trying to accomplish.

Are you trying to put your sum formula in every used cell in column D? Or are you simply summing the values in column D?
0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 37718331
Sub possibleSolution()

    'The following will put your sum formula in the next available cell in column D.

    'declare a string variable to hold your formula
    Dim formulaString As String
    
    'populate formulaString with formula
    formulaString = "=sum(d2:d" & Range("d" & Rows.Count).End(xlUp).Row - 1 & ")"
    Debug.Print Now & formulaString
    
    'put the formula in the next available cell in column d
    Range("d" & Rows.Count).End(xlUp).Formula = formulaString
    
End Sub

Open in new window

0
 

Author Closing Comment

by:BigWill5112
ID: 37719489
Had to do with the and symbol and spaces apparently.  thanks.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now