LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Pank
 
Posts: n/a
Default Help with Countrows functionality within a Macro

I recently, found that I needed a mechanism to count the number of rows that
existed in each worksheet.

I discovered that the COUNTROWS functionality was just what I wanted.

I decided that I would insert the functionality into a macro, which is used
on a quarterly basis that basically, merges three sheets, then creates
individual sheets for each company and finally undertakes Page formatting.

Within the format macro I inserted the following:- (thank you to Dave Ramage)

Sub DoStuff()
Dim wks as Worksheet
Dim lLastRow as Long

For Each wks in Activeworkbook.Worksheets
lLastRow = wks.Range("A1").End(xlDown).Row
wks.PageSetup.PrintArea = "$A$1:$K$" & lLastRow
wks.Cells(lLastRow + 1, 1).Formula = "TOTAL"
wks.Cells(lLastRow + 1, 2).Formula = "=COUNTROWS(A:A) €“ 2"
€˜the €“2 at the end is to discard one header line, and the countrows line
Next wks
End Sub

Unfortunately when I run it, I get a €˜Run-time error 1004 €“
Application-defined or object-defined error.

I have had a look at it, and word TOTAL is inserted in the last row in
Column A for the very first sheet only. It then gives the above error. The
line it seems to complain about is wks.Cells(lLastRow + 1, 2).Formula =
"=COUNTROWS(A:A) €“ 2"

Any suggestions would be most welcome

Regards

Pank

 
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
Help with macro looping and color query function kevinm Excel Discussion (Misc queries) 10 May 26th 05 01:25 AM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
Macro for multiple charts JS Excel Worksheet Functions 1 November 19th 04 03:44 AM


All times are GMT +1. The time now is 10:24 PM.

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"