Hi Everyone,
I started learning VBA 2 days ago and I'm having trouble with something.
I am trying to create a macro for calculating Gross Margin and have used the code below. Is this correct? Also, when I go and click on the "Macros" tab under the "Developer" tab, I can't see this macro ("GrossMargin1")?
Any help with this would be greatly appreciated!!! BTW, everything except for lines 3,4,5,6 were in a book I am reading so I added these particular lines to get the formula working.
Thank you!!
Giri
[VBA]Public Function GrossMargin1()
Dim totalSales
Dim totalExpenses
Dim sales As Range
Dim expenses As Range
Set sales = Sheet1.Range("D22", "F22")
Set expenses = Sheet1.Range("D24", "F24")
totalSales = Application.Sum(Range("Sales"))
totalExpenses = Application.Sum(Range("Expenses"))
GrossMargin1 = (totalSales - totalExpenses) / totalSales
End Function[/VBA]