Prev Previous Post   Next Post Next
  #6   Report Post  
Gary''s Student
 
Posts: n/a
Default

You could replace the Msgbox with a
Cells(1,1).Value = count
to put the result in A1, for example.
--
Gary's Student


"dave" wrote:

How would i get it to populate a cell with the total instead on getting it to
appear in a message box ?

"Gary''s Student" wrote:

The Cells.select statement selects all the cells in the worksheet. This is
the range that is being examined. Note that, as coded, we start in A1 and go
across rows and then down, counting as we go.

If B2 contains "end", the routine will return 257
--
Gary's Student


"dave" wrote:

Thanks for that, if i wanted to be more specific in what i count, do i just
changed the Cells.Select statement ?

"Gary''s Student" wrote:

Enter and run this macro:

Sub Macro1()
Dim r As Range
Dim count As Long
Cells.Select
For Each r In Selection
If r.Value = "end" Then
Exit For
Else
count = count + 1
End If
Next
MsgBox (count)
End Sub
--
Gary''s Student


"dave" wrote:

I need to count the number of cells in a worksheet until it reaches a
specific value.
i.e count the number of cells until it reaches a cell containing the word
'end'

 
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
Counting shaded cells demon42 Excel Worksheet Functions 2 September 21st 05 08:56 PM
Counting filled cells in excel Alex Wilson Excel Worksheet Functions 5 September 19th 05 11:01 PM
Counting the number of cells meeting conditional formating criteria Jeff Excel Worksheet Functions 4 July 9th 05 01:18 AM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 2 May 2nd 05 08:53 AM
complex fomula: counting cells that are blank shmurphing Excel Worksheet Functions 2 January 6th 05 09:55 PM


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