Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 09-13-2004, 09:36 PM   #1
Member (9 bit)
 
Join Date: Oct 2003
Location: Minnesota, USA
Posts: 382
Send a message via AIM to MrAustin
Excel VBA Question

Hello all,

I am making a tracking sheet for work, and am stumped on this VBA stuff (for now, hehe ) At any rate, here is what is to be accomplished.

There are several column headers, of which there will be placed an AutoFilter on each one. Above the Amount column, I want a button that will sum the contents of the cells in that column (F3:End, lets say). Does anyone here know how to:

1. Figure out the last cell in the column that has data in it with VBA?
2. Sum the figures from F3:LastCell?
3. Pop-up a MsgBox with the Sum in it? (this step I think I can do, but I've no idea how to get the value to be displayed)

I would greatly appreciate any insights into this as I learn this awesome language.
MrAustin is offline   Reply With Quote
Old 09-28-2004, 01:10 PM   #2
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
Paste this into an Excel macro and run it:
_________________________________
Code:
Public Sub Sigma()
    Dim strCol As String
    Dim intRow As Integer
    Dim sngSum As Single
    
    strCol = "A" 'enter the column letter here
    intRow = 3 'enter the row the values start on
    sngSum = 0
    
    'while condition tests if the cell is not empty
    'cell format is A1, A2, A3, etc.
    While Trim(CStr(Range(strCol & intRow).Value)) <> ""
        'cast the value of the cell to a single and add
        sngSum = sngSum + CSng(Range(strCol & intRow).Value)
        intRow = intRow + 1
    Wend
    
    'once we get here, we have processed all the values
    Range(strCol & intRow).Value = sngSum 'display the sum in the cell
    
    'show a message box
    MsgBox sngSum, vbOKOnly + vbInformation, "The sum is"

End Sub
faulkner132 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:53 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2