Hi Jeff, good decision! This problem looked familiar and the code below works for me. Two things, you may want to change the msgbox to a more appropriate message. Second, I put extra code in here to make your average number bolded, simply change the 'false' to true (delete this line if you don't want it. Good luck.
Cheers!
Sub Pretty_Average()
If Range("j1") <> "" Then
Range("j1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="Money", RefersToR1C1:=Selection
Range("j1").Select
If Range("j2") <> "" Then
Selection.End(xlDown).Select
End If
Selection.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "=average(Money)"
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
Selection.Font.Bold = False
ActiveWorkbook.Names("Money").Delete
Range("a1").Select
Else: Range("a1").Select
MsgBox prompt:="Looks like someone forgot the data...Show me the Data.", _
title:="Oops..."
End If
End Sub
Probably should add one more if statement
This is better
Sub Pretty_Average()
If Range("j1") <> "" Then
Range("j1").Select
If Range("j2") <> "" Then
Range(Selection, Selection.End(xlDown)).Select
End If
ActiveWorkbook.Names.Add Name:="Money", RefersToR1C1:=Selection
Range("j1").Select
If Range("j2") <> "" Then
Selection.End(xlDown).Select
End If
Selection.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "=average(Money)"
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
Selection.Font.Bold = False
ActiveWorkbook.Names("Money").Delete
Range("a1").Select
Else: Range("a1").Select
MsgBox prompt:="Looks like someone forgot the data...Show me the Data.", _
title:="Oops..."
End If
End Sub
Cheers!
Re: Probably should add one more if statement
Thanks a lot for your help, Nate. After a little tweaking to meet my exact needs, this worked like a charm.
Jeff
Re: Probably should add one more if statement
You're welcome. Regards,
Nate Thanks a lot for your help, Nate. After a little tweaking to meet my exact needs, this worked like a charm. Jeff : This is better :