Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Referencing a Column in a Selected Range of Columns

Hi,

Using VBA code, how could I select a bunch of columns that may or may not be
continuous, and return a sum (or any function) from each column?

For example, I select Columns A,B, D, and E. The procedure (maybe in a
msgbox) returns:
A total = 100
B total = 200
D total = 150
E total = 175

Thanks for your help.

-Rob

p.s. The specific problem I am having is returning which column I selected.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Referencing a Column in a Selected Range of Columns

Sub ShowTotals()
Dim rng As Range, ar As Range
Dim col As Range, sStr as String
Set rng = Selection.EntireColumn
For Each ar In rng
For Each col In ar
sStr = sStr & Left(col.Address(0, 0), 1 - (col.Column 26))
sStr = sStr & " total = " & Format(Application.Sum(col), "#,###.00")
sStr = sStr & vbNewLine
Next
Next

MsgBox sStr

End Sub

--
Regards,
Tom Ogilvy



"Rob G" wrote in message
...
Hi,

Using VBA code, how could I select a bunch of columns that may or may not

be
continuous, and return a sum (or any function) from each column?

For example, I select Columns A,B, D, and E. The procedure (maybe in a
msgbox) returns:
A total = 100
B total = 200
D total = 150
E total = 175

Thanks for your help.

-Rob

p.s. The specific problem I am having is returning which column I

selected.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Referencing a Column in a Selected Range of Columns

That is just perfect!

Thank you!


"Tom Ogilvy" wrote in message
...
Sub ShowTotals()
Dim rng As Range, ar As Range
Dim col As Range, sStr as String
Set rng = Selection.EntireColumn
For Each ar In rng
For Each col In ar
sStr = sStr & Left(col.Address(0, 0), 1 - (col.Column 26))
sStr = sStr & " total = " & Format(Application.Sum(col), "#,###.00")
sStr = sStr & vbNewLine
Next
Next

MsgBox sStr

End Sub

--
Regards,
Tom Ogilvy



"Rob G" wrote in message
...
Hi,

Using VBA code, how could I select a bunch of columns that may or may

not
be
continuous, and return a sum (or any function) from each column?

For example, I select Columns A,B, D, and E. The procedure (maybe in a
msgbox) returns:
A total = 100
B total = 200
D total = 150
E total = 175

Thanks for your help.

-Rob

p.s. The specific problem I am having is returning which column I

selected.







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Referencing a Column in a Selected Range of Columns

Actually, that should have been:

Sub ShowTotals()
Dim rng As Range, ar As Range
Dim col As Range
Set rng = Intersect(Cells, Selection.EntireColumn)
For Each ar In rng.Areas
For Each col In ar.Columns
sStr = sStr & Left(col.Address(0, 0), 1 - (col.Column 26))
sStr = sStr & " total = " & Format(Application.Sum(col), "#,###.00")
sStr = sStr & vbNewLine
Next
Next

MsgBox sStr

End Sub

--
Regards,
Tom Ogilvy




"Tom Ogilvy" wrote in message
...
Sub ShowTotals()
Dim rng As Range, ar As Range
Dim col As Range, sStr as String
Set rng = Selection.EntireColumn
For Each ar In rng
For Each col In ar
sStr = sStr & Left(col.Address(0, 0), 1 - (col.Column 26))
sStr = sStr & " total = " & Format(Application.Sum(col), "#,###.00")
sStr = sStr & vbNewLine
Next
Next

MsgBox sStr

End Sub

--
Regards,
Tom Ogilvy



"Rob G" wrote in message
...
Hi,

Using VBA code, how could I select a bunch of columns that may or may

not
be
continuous, and return a sum (or any function) from each column?

For example, I select Columns A,B, D, and E. The procedure (maybe in a
msgbox) returns:
A total = 100
B total = 200
D total = 150
E total = 175

Thanks for your help.

-Rob

p.s. The specific problem I am having is returning which column I

selected.







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
change color to selected columns in a stacked column chart Noa Charts and Charting in Excel 2 April 28th 23 07:45 PM
Multiple cells or columns are selected instead of selected cell or Mikey Excel Discussion (Misc queries) 1 April 29th 09 09:48 PM
referencing selected cells [email protected] Excel Worksheet Functions 2 September 27th 06 07:22 PM
Choose data from a selected range and put result in new column Betsy Excel Worksheet Functions 2 July 1st 06 04:13 AM
Referencing a range of columns and rows with the IF function Cliff Excel Worksheet Functions 7 April 2nd 06 01:07 AM


All times are GMT +1. The time now is 11:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"