#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 34
Default Count Rows macro

I am trying to write a macro that will do the following:

Count the number of used rows in my worksheet and assign it a name or
variable.

Then i would like to Select Column K and enter a "1" in K7. From there i
want to do an autofill to the last used from as determined above.

The number of rows changes with each spreadsheet and I have gotten this work
for one, but the next one doesn't quite work because there are more rows.

Any help would be great.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Count Rows macro

Option Explicit
sub TestMe()

Dim LastRow as long

with worksheets("sheet9999")
lastrow = .cells(.rows.count,"A").end(xlup).row
with .range("k1:K" & lastrow)
.formula = "=row()"
.value = .value
end with
end with
End sub

I used column A to find the last used row in the worksheet. And I used
Sheet9999 as the sheet name--change each as required.

MikeD1224 wrote:

I am trying to write a macro that will do the following:

Count the number of used rows in my worksheet and assign it a name or
variable.

Then i would like to Select Column K and enter a "1" in K7. From there i
want to do an autofill to the last used from as determined above.

The number of rows changes with each spreadsheet and I have gotten this work
for one, but the next one doesn't quite work because there are more rows.

Any help would be great.

Thanks


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Count Rows macro

If you want autofil by 1 only:

Sub miked()
Set r = ActiveSheet.UsedRange
last = r.Rows.Count + r.Row - 1
For i = 7 To last
Cells(i, "K").Value = 1
Next
End Sub


If you want autofil with ascending numbers:

Sub miked2()
Set r = ActiveSheet.UsedRange
last = r.Rows.Count + r.Row - 1
j = 1
For i = 7 To last
Cells(i, "K").Value = j
j = j + 1
Next
End Sub

--
Gary's Student
gsnu200707


"MikeD1224" wrote:

I am trying to write a macro that will do the following:

Count the number of used rows in my worksheet and assign it a name or
variable.

Then i would like to Select Column K and enter a "1" in K7. From there i
want to do an autofill to the last used from as determined above.

The number of rows changes with each spreadsheet and I have gotten this work
for one, but the next one doesn't quite work because there are more rows.

Any help would be great.

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 34
Default Count Rows macro


Thank you. That was exactly what I was looking for.

Mike

"Gary''s Student" wrote:

If you want autofil by 1 only:

Sub miked()
Set r = ActiveSheet.UsedRange
last = r.Rows.Count + r.Row - 1
For i = 7 To last
Cells(i, "K").Value = 1
Next
End Sub


If you want autofil with ascending numbers:

Sub miked2()
Set r = ActiveSheet.UsedRange
last = r.Rows.Count + r.Row - 1
j = 1
For i = 7 To last
Cells(i, "K").Value = j
j = j + 1
Next
End Sub

--
Gary's Student
gsnu200707


"MikeD1224" wrote:

I am trying to write a macro that will do the following:

Count the number of used rows in my worksheet and assign it a name or
variable.

Then i would like to Select Column K and enter a "1" in K7. From there i
want to do an autofill to the last used from as determined above.

The number of rows changes with each spreadsheet and I have gotten this work
for one, but the next one doesn't quite work because there are more rows.

Any help would be great.

Thanks

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
match week, count rows, sum rows? earls Excel Worksheet Functions 2 January 5th 07 02:34 AM
Count number of rows, where non relevant rows are hidden Pieter Excel Discussion (Misc queries) 2 November 8th 06 12:24 PM
Count rows and insert number to count them. Mex Excel Discussion (Misc queries) 6 August 23rd 06 02:29 AM
count colored rows NoviceLois Excel Discussion (Misc queries) 1 December 28th 05 11:52 PM
Why does rngDataSource.Rows.Count = 65536 when worksheet Rows=95? [email protected] Excel Discussion (Misc queries) 12 July 22nd 05 12:50 PM


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