LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default vba code for subtotals and percentages

Since you are using your local format for R1C1 notation, you need to

Change FormulaR1C1 to FormulaR1C1Local

otherwise, you can keep FormulaR1C1 and change your "d" 's to "c" 's

--
Regards,
Tom Ogilvy


"pcscsr" wrote in message
...

I have the following code that when the user clicks on the command
button the selected items are transferred to a separte sheet along with
the calculations. The first part (transferring the selected items)
works great. However, I get a application-defined or object defined
error in the 2nd part. (where ".formula" starts). Is there anyone
that can help me with this? I'd a appreciate greatly as I am under a
deadline. Thank you.

Private Sub CommandButton1_Click()
Dim i As Integer, x As Integer
Dim n As Integer, r As Range
i = 2
Sheets("sheet2").Range("a:d").EntireColumn.ClearCo ntents
With ListBox1
For x = 0 To .ListCount - 1
If .Selected(x) = True Then
For j = 1 To .ColumnCount
Sheets("sheet2").Cells(i, j).Value = .List(x, j - 1)
Next
i = i + 1
End If
Next x
End With

n = 10
Set r = Range("d2:d" & n)
r.Value = 2
n = n + 1
Cells(n, 2) = "subtotal"
Cells(n, 3).FormulaR1C1 = "=sum(r2d:r[-1]d)"
n = n + 1
Cells(n, 2) = "'+6%"
Cells(n, 3).FormulaR1C1 = "=.6*r[-1]d"
n = n + 1
Cells(n, 2) = "subtotal"
Cells(n, 3).FormulaR1C1 = "=r[-2]d + r[-1]d"
n = n + 1
Cells(n, 2) = "' + 35%"
Cells(n, 3).FormulaR1C1 = "=.35*r[-1]d"
n = n + 1
Cells(n, 2) = "subtotal"
Cells(n, 3).FormulaR1C1 = "=r[-2]d + r[-1]d"
n = n + 1
Cells(n, 2) = "' + 10%"
Cells(n, 3).FormulaR1C1 = "=.1*r[-1]d"
n = n + 1
Cells(n, 2) = "Grand total"
Cells(n, 3).FormulaR1C1 = "=r[-2]d + r[-1]d"

UserForm1.Hide
End Sub


--
pcscsr
------------------------------------------------------------------------
pcscsr's Profile:

http://www.excelforum.com/member.php...o&userid=12006
View this thread: http://www.excelforum.com/showthread...hreadid=274838



 
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
Percentages of Subtotals for Pivot Tables Craig Excel Discussion (Misc queries) 2 July 26th 08 07:32 PM
Subtotals problem: Excel 2003 (not, AFAIK, the nested subtotals bug) AndyCotgreave Excel Discussion (Misc queries) 3 October 24th 07 11:32 AM
percentages of subtotals Miaplacidus Excel Worksheet Functions 1 May 31st 07 08:29 PM
Calculating percentages in pivot tables on subtotals David Ruderman - Chapman University Excel Worksheet Functions 1 November 24th 05 04:54 PM
**HELP** VBA code to insert subtotals farmer[_2_] Excel Programming 1 May 28th 04 08:24 PM


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

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

About Us

"It's about Microsoft Excel"