my first macro

D

DALE

I am experimenting with my first macros, so excuse my ignorance. I
want to create a calculated column of data and a total. I want the
macro to work no matter how many rows of data are in the sheet. Seems
that when I create the macro using absolute or relative I get the same
result, the marco only works for the exact number of rows when I
recorded it... any suggestions?

Dale
 
G

Gord Dibben

Dale

This macro will add a total formula at the cell below your used range in
column B.

Sub SumupB()
Dim Rng As Range
Set Rng = Range("B1", Range("B" & Rows.Count). _
End(xlUp).Address)
Set rng1 = Rng.Offset(Rng.Rows.Count, 0).Resize(1, 1)
rng1.Formula = "=Sum(" & Rng.Address & ")"
End Sub

As for the Macro Recorder and relative/absolute recording.......it just
doesn't quite do the job expected but should give you an idea.

For a few examples of how to translate the Macro Recorder code and spruce it
up see Tushar Mehta's site. Scroll down to VBA "Beyond the Macro Recorder".

http://www.tushar-mehta.com/

Gord Dibben Excel MVP XL2002
 

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