Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory monitor motherboard network operating system printer problem ram registry router slow software sound svchost.exe toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Macro Weighted Average

Reply  
Thread Tools
Akuller's Avatar
Member with 115 posts.
 
Join Date: Feb 2004
Location: Northern Calif
02-Sep-2010, 11:15 PM #1
Macro Weighted Average
Hi, I'm using Excel 2003, and I've built a macro to do various things, one of them to add subtotals based on the change in data. I simply used the function under Data>subtotals to do the summing but I need one column to sum and then divide by the column next to it in order to give a weighted average.

I do not know VBA, but is there an easy way to do this?

Thanks!
__________________
AK
Zack Barresse's Avatar
Computer Specs
Distinguished Member with 5,030 posts.
 
Join Date: Jul 2004
Location: Oregon, United States
Experience: I'ma learnin'!
05-Sep-2010, 03:19 AM #2
Hi there,

Do you have a sample of your data? And can you please post your code? If the data is not your data, please make sure the structure is equivalent. But yes, to answer your question, there is a way to do it, and it should be fairly easy.
Akuller's Avatar
Member with 115 posts.
 
Join Date: Feb 2004
Location: Northern Calif
08-Sep-2010, 03:54 PM #3
Current macro:

Cells.Select
With Selection
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Rows("1:8").Select
Selection.Delete Shift:=xlUp
Range("O1").Select
ActiveSheet.Shapes("CwusLogo.jpeg").Select
Selection.Delete
Cells.Select
Range("F1").Activate
Selection.Sort Key1:=Range("F2"), Order1:=xlAscending, Key2:=Range("J2") _
, Order2:=xlAscending, Key3:=Range("K2"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortTextAsNumbers
Range("A3").Select
Selection.End(xlUp).Select
Range("A2").Select
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=18
Rows("4851:5971").Select
Selection.ClearContents
Columns("S:S").Select
Selection.Insert Shift:=xlToRight
Range("S1").Select
ActiveCell.FormulaR1C1 = "^Wt. Avg"
Range("S2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*RC[-2]"
Range("S2").Select
Selection.AutoFill Destination:=Range("S2:S4850")
Range("S2:S4850").Select
Columns("S:S").EntireColumn.AutoFit
Range("K7").Select
Selection.Subtotal GroupBy:=9, Function:=xlSum, TotalList:=Array(14, 15, 16, _
17, 19), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Range("A1").Select


Would now like to make the change to all subtotals under Column "S", WT. Avg, to have that subtotal divided by subtotal in column Q, amount. So the subtotal for Wt. Avg (548.28)/subtotal for amount (33.16) should give wt.avg of (16.53). It is the 16.53 I'd like to see, even if I have to insert a new column next to Wt. Avg (T). I'd like this to calculate within the macro at each section that has a subtotal.
Q R S T
amount amt.per Wt. Avg
10.36 16.3 168.868
13.39 16.6 222.274
9.41 16.7 157.147
33.16 548.289 16.5

Let me know if this is asking too much...thanks!
__________________
AK
Zack Barresse's Avatar
Computer Specs
Distinguished Member with 5,030 posts.
 
Join Date: Jul 2004
Location: Oregon, United States
Experience: I'ma learnin'!
08-Sep-2010, 06:16 PM #4
Do you have a sample file you can post? Data would help...
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools


Similar Threads
Title Thread Starter Forum Replies Last Post
Solved: Excel Macro to Update Outlook Calendar Creates Duplicates lessanj2 Business Applications 4 09-Sep-2010 08:12 PM
Solved: Macro to insert a Row dstreng Business Applications 2 17-Apr-2009 10:40 AM
Weighted Average of Every Other Column With Data excelgamine Business Applications 3 24-Mar-2009 10:38 AM
Solved: Time-weighted average in Excel azim_yunos Business Applications 7 22-Mar-2009 07:56 PM
Excel-Stopping and Starting a Running Average in a Column lyncur Business Applications 6 05-Feb-2009 06:26 AM


Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:27 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.