Avatar of BigWill5112
BigWill5112

asked on 

vba code

Why will this not work?  AHHH

Range("d" & Rows.Count).End(xlUp).Formula = "=sum(d2:"&Range("d" & Rows.Count).End(xlUp).Range")"
Visual Basic Classic

Avatar of undefined
Last Comment
BigWill5112
ASKER CERTIFIED SOLUTION
Avatar of Anthony Berenguel
Anthony Berenguel
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
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?
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

Avatar of BigWill5112
BigWill5112

ASKER

Had to do with the and symbol and spaces apparently.  thanks.
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo