Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Row number for End of Template

I have a data gathering template used in our department and the length of the
template could vary. Regardless of the length though, the row at the end of
the template will have the word TOTAL in column C of that row.

The USer can still add text into rows below the one identified as the end of
the template i.e. if cell C69 has the word, Total, then row 69 will be
assumed to be the ned of the template regardless of how many non-empty rows
are after that.

I tried to write a code to identify the end of the template(see below) but
it is not working. The Do Loop wasn't exited. ANy help will be appreciated.

Pele


Worksheets(2).Activate
s = 0
Do
s = s + 1
Cells(s, 3).Select
z = Cells(s, 3)
If z = "total" Then
Exit Do
End If
Loop
Size = z

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Row number for End of Template

Hi Pele,

You could use the Find method to do this:

Dim rng As Range

Set rng = Columns(3).Find(What:="total")
If Not rng Is Nothing Then MsgBox rng.Row

Set rng = Nothing

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

Pele wrote:
I have a data gathering template used in our department and the
length of the template could vary. Regardless of the length though,
the row at the end of the template will have the word TOTAL in column
C of that row.

The USer can still add text into rows below the one identified as the
end of the template i.e. if cell C69 has the word, Total, then row 69
will be assumed to be the ned of the template regardless of how many
non-empty rows are after that.

I tried to write a code to identify the end of the template(see
below) but it is not working. The Do Loop wasn't exited. ANy help
will be appreciated.

Pele


Worksheets(2).Activate
s = 0
Do
s = s + 1
Cells(s, 3).Select
z = Cells(s, 3)
If z = "total" Then
Exit Do
End If
Loop
Size = z



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Row number for End of Template

Thanks...

"Jake Marx" wrote:

Hi Pele,

In order to match a cell's value exactly, you can specify another argument
to the Find method:

Set rng = Columns(3).Find(What:="total", LookAt:=xlWhole)

To store it as a variable, use a Long:

Dim lEndRow As Long

And assign it to the variable instead of using MsgBox:

If Not rng Is Nothing Then lEndRow = rng.Row

Now for your code:

s = 0
z = Cells(s, 3).Value


This won't work, as cells is 1-based (0 means row zero, which doesn't make
sense).

Do
s = s + 1
Cells(s, 3).Select
z = Cells(s, 3)


There's no need to Select anything here - just use z = Cells(s, 3).Value.

If z = "total" Then


String comparisons are case-sensitive by default. So if your cell value has
"Total" or "TOTAL", this won't return True. To do a case-insensitive match,
you can use StrComp():

If StrComp(z, "total", vbTextCompare) = 0 Then
'/ match
Else
'/ no match
End If

That said, a Find will be much quicker than iterating over the cells in the
column.

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

Pele wrote:
Jake,

I tried this solution but it didn't work the way I wanted. I wanted
to find the cell that said exactly "TOTAL" as opposed to "TOTAL
SUPPLY".

I also need to capture the row number as a variable to use in another
line of code (as opposed to it being displayed in a message box). I
am not that good at macro.

By the way, can you tell me why the code I'd written didn't work (see
below).

Pele


<snip



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
Automatically use next number on a template Nenagh Excel Discussion (Misc queries) 1 June 11th 09 08:12 AM
Template Wizard - Number of fields Randy Cole Excel Discussion (Misc queries) 0 June 8th 06 09:20 PM
How do i number a template so that it will increase 1,2,3 etc? Dreamworks New Users to Excel 1 July 28th 05 11:43 AM
How do I set up a template to assign a unique number? Feltonblue Excel Programming 3 October 5th 04 06:55 PM
How do I set up an Excel template to generate a new number every . Tom Ogilvy Excel Programming 0 September 15th 04 05:24 PM


All times are GMT +1. The time now is 06:00 PM.

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"