Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Problem with basic looping and criteria

I am trying to loop through a range and count the number of time a cell
contains the letters"CPCT". I am using the right function since they always
occur at the end of the string. My cod keeps getting snagged he If
xlApp.WorksheetFunction.Right(r1.Value, 4) = "CPCT" Then

Any Ideas? My full code is below
Dim r1 As Range
Dim Count As Integer
Count = 0
For Each r1 In xlApp.Sheets("Resource Info").Range("A4:A500")
If xlApp.WorksheetFunction.Right(r1.Value, 4) = "CPCT" Then
Count = Count + 1
End If
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Problem with basic looping and criteria

Sub What()
Count = 0
Range("A4").Select
Do Until ActiveCell.Address = "$A$500"
If Right(ActiveCell.Value, 4) = "CPCT" Then
Count = Count + 1
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub


"Jeff" wrote:

I am trying to loop through a range and count the number of time a cell
contains the letters"CPCT". I am using the right function since they always
occur at the end of the string. My cod keeps getting snagged he If
xlApp.WorksheetFunction.Right(r1.Value, 4) = "CPCT" Then

Any Ideas? My full code is below
Dim r1 As Range
Dim Count As Integer
Count = 0
For Each r1 In xlApp.Sheets("Resource Info").Range("A4:A500")
If xlApp.WorksheetFunction.Right(r1.Value, 4) = "CPCT" Then
Count = Count + 1
End If
Next

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Problem with basic looping and criteria

Try this...

Dim r1 As Range
Dim Count As Integer
Count = 0
For Each r1 In Range("A4:A500")
If Right(r1.Value, 4) = "CPCT" Then
Count = Count + 1
End If
Next
MsgBox "total = " & Count

"Jeff" wrote:

I am trying to loop through a range and count the number of time a cell
contains the letters"CPCT". I am using the right function since they always
occur at the end of the string. My cod keeps getting snagged he If
xlApp.WorksheetFunction.Right(r1.Value, 4) = "CPCT" Then

Any Ideas? My full code is below
Dim r1 As Range
Dim Count As Integer
Count = 0
For Each r1 In xlApp.Sheets("Resource Info").Range("A4:A500")
If xlApp.WorksheetFunction.Right(r1.Value, 4) = "CPCT" Then
Count = Count + 1
End If
Next

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
Macro for Looping for Criteria Checking FARAZ QURESHI Excel Discussion (Misc queries) 5 June 22nd 07 03:19 AM
Looping Problem . . .Argh! ed Excel Programming 6 December 17th 04 04:18 PM
If Then Else looping problem Kieran1028[_12_] Excel Programming 1 November 11th 04 06:27 PM
multiple looping criteria hotherps[_62_] Excel Programming 2 May 30th 04 12:57 AM
Looping Problem Todd Huttenstine[_3_] Excel Programming 5 January 25th 04 12:51 AM


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