I need a macro

P

pcor

I would like a macro to do the following:
I would place the the cursor in any cell and this macro would give me the
average of all the entries to the left if the selected cell. EX: I place the
cursor in cell M12.
I want this macro on display in cell M12 the average of all the values from
Col C12 to Col L12. Note that there may NOT be entries in all the cells in
that range. Also the start point would always be col C .Thanks
 
D

Don Guillett

You can do this easily with a worksheet_selection event in the sheet module
but you would probably want to restrict to a certain range or columns and
rows or it would fire EACH time you select ANY cell. Never less than col C
and never more than column _____? rows________?
 
P

pcor

Thanks for thr quick reply....BUT can you please tell me HOW to accomplish
that!
Thanks
 
D

Don Guillett

Right click sheet tab>view code>insert this>adjust columns/rows>SAVE
workbook.
Now if you select a cell within the allowed area you will get your average.
Please note that you will have difficulty putting info into the cells so you
may want to comment out the macro to do that.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row <12 Or Target.Row > 25 _
Or Target.Column < 3 Or Target.Column > 14 Then Exit Sub
tr = Target.Row
tc = Target.Column - 1
MsgBox Application.Average(Range(Cells(tr, 3), Cells(tr, tc)))
End Sub
 

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