Macro help

I

igotquestions

I am trying to create a macro that will add the dollar values in a specific
column. The problem I am having is that the number of vaules in that column
vary depending on the worksheet. Ex. Worksheet 1 has 20 dollar values while
worksheet 2 has 60 dollar values.

How can I create a macro that will, autosense if you will, the number of
values in a specifc column and adjust the formula to meet the needs of
different spreadsheets?
 
D

Don Guillett

Since you don't fully explain, I'm doing some guessing here. This will go
thru all worksheets after sheet1 and total c2:c last row and put the total
in c1

Sub totalvariablecolumn()
For i = 2 To Worksheets.Count
With Sheets(i)
lr = .Cells(rows.Count, "c").End(xlUp).Row
mysum = Application.Sum(.Range("c2:c" & lr))
'MsgBox mysum
..Cells(1, "c") = mysum
End With
Next i
End Sub
 
I

igotquestions

Forgive me I am new to this. My situation is:
I use Access to keep job info. One of my forms gives me my parts with dollar
amounts for each job. I analyze this form in Excel. The dollar amounts always
start at cell O4 and proceed down until all of the parts are covered. This
length varies depending on the amount of parts that are in each job. I am
trying to create a macro that I can use to give the the total dollar amount
for all of the parts starting at cell O4 and outputting the total to cell D2.
The variable is the ending cell for the parts dollars. How would I tell the
macro to add everything from O4 down to last dollar amount?

This may be way above my head to comprehend so any help would greatly be
appreciated
 
M

Mike H

Hi,

If Don will excuse me for altering his macro try this. Right click your
sheet tab, view code and paste this in and run it

Sub totalvariablecolumn()
With Sheets("Sheet1") 'Change to suit
lr = .Cells(Rows.Count, "O").End(xlUp).Row
mysum = Application.Sum(.Range("O4:O" & lr))
End With
Range("D2").Value = mysum
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top