Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default inserting subtotal() function in spreadsheet via Visual Basic/macro

I want to be able to execute a macro (stored in PERSONAL.XLS) that puts the following statement in the cell two rows below the bottom row of a worksheet (regardless of how many rows)
=SUBTOTAL(3,A2,Axxxx
where xxxx is the last populated row. The following gets most of the way there
Set dataSheet = ActiveShee
totalrows = dataSheet.UsedRange.Rows.Coun
startrow = totalrows +
Range("A" + CStr(startrow)).FormulaR1C1 = "=SUBTOTAL(3,A2:R[-2]C[0])
The above puts the following in the correct cell, but I can't figure out how to get A2 and not 'A2
=SUBTOTAL(3,'A2':A3839) && where 3839 happens to be the last row and is what I want

Can anyone help

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default inserting subtotal() function in spreadsheet via Visual Basic/macro

Try this:

Range("A" + CStr(startrow)).FormulaR1C1 = "=SUBTOTAL(3,R[-" & CStr(startrow - 1) & "]C[0]:R[-2]C[0])"

I had to do a -1 because apparently if you go up to far, it will start over at the bottom (I kept getting 65536 with just startrow).
"darrelstickler" wrote in message ...
I want to be able to execute a macro (stored in PERSONAL.XLS) that puts the following statement in the cell two rows below the bottom row of a worksheet (regardless of how many rows).
=SUBTOTAL(3,A2,Axxxx)
where xxxx is the last populated row. The following gets most of the way the
Set dataSheet = ActiveSheet
totalrows = dataSheet.UsedRange.Rows.Count
startrow = totalrows + 2
Range("A" + CStr(startrow)).FormulaR1C1 = "=SUBTOTAL(3,A2:R[-2]C[0])"
The above puts the following in the correct cell, but I can't figure out how to get A2 and not 'A2'
=SUBTOTAL(3,'A2':A3839) && where 3839 happens to be the last row and is what I want.

Can anyone help?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default inserting subtotal() function in spreadsheet via Visual Basic/macro

Sorry, just noticed you wanted A2 and not A1, so either put (startrow - 2) or (totalrows)

Range("A" + CStr(startrow)).FormulaR1C1 = "=SUBTOTAL(3,R[-" & CStr(totalrows) & "]C[0]:R[-2]C[0])"

"Medemper" wrote in message ...
Try this:

Range("A" + CStr(startrow)).FormulaR1C1 = "=SUBTOTAL(3,R[-" & CStr(startrow - 1) & "]C[0]:R[-2]C[0])"

I had to do a -1 because apparently if you go up to far, it will start over at the bottom (I kept getting 65536 with just startrow).
"darrelstickler" wrote in message ...
I want to be able to execute a macro (stored in PERSONAL.XLS) that puts the following statement in the cell two rows below the bottom row of a worksheet (regardless of how many rows).
=SUBTOTAL(3,A2,Axxxx)
where xxxx is the last populated row. The following gets most of the way the
Set dataSheet = ActiveSheet
totalrows = dataSheet.UsedRange.Rows.Count
startrow = totalrows + 2
Range("A" + CStr(startrow)).FormulaR1C1 = "=SUBTOTAL(3,A2:R[-2]C[0])"
The above puts the following in the correct cell, but I can't figure out how to get A2 and not 'A2'
=SUBTOTAL(3,'A2':A3839) && where 3839 happens to be the last row and is what I want.

Can anyone help?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default inserting subtotal() function in spreadsheet via Visual Basic/macro

That's amazing. Thanks. Don't know where you learned the syntax, but I'm just a beginning swimming in shark infested waters. :)
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
Are there any NON-Visual Basic solutions for inserting a picture based a derived or called filename? The Great Attractor Excel Worksheet Functions 7 May 27th 07 04:38 AM
Loading a linked spreadsheet, Microsoft Visual Basic, error while. Wacher Excel Discussion (Misc queries) 0 April 18th 05 03:15 PM
Visual Basic Macro negzel Excel Discussion (Misc queries) 1 December 28th 04 10:53 PM
Visual Basic macro to do something that is done trhough an Excel function Thierry[_2_] Excel Programming 2 December 11th 03 08:58 AM
using visual basic controls in a excel web page saved spreadsheet Mike Murschel Excel Programming 0 October 14th 03 03:17 PM


All times are GMT +1. The time now is 02:21 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"