subtracting columns in a macro

V

Vel

I would like to subtract one column from another in the
macro I am creating. Can someone tell me how to do that
when the number of rows in the spreadsheet will always
vary?
Thanks so much!
 
F

Frank Kabel

Hi Vel
one simple idea: Subtract the whole columns from each other:
application.WorksheetFunction.Sum(range("A:A")) -
application.WorksheetFunction.Sum(range("B:B"))

Frank
 
T

Tom Ogilvy

Assume you want to subtract Column A from column B and Column A will
determine the number of cells and first value is in A1

Dim rng as Range
Set rng = Range(Cells(1,1),Cells(rows.count,1).End(xlup))
rng.copy
Range("B1").Pastespecial paste:=xlPasteValues, _
Operation:=xlPasteSpecialOperationSubtract

Might want to post programming question in

news://msnews.microsoft.com/microsoft.public.excel.programming
 

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