Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Search for text in a cell

In column B of my spreadsheet i have descriptions that are about twent
or so words long. I want to count the one's that contain specific tex
such as "Gate 4" contained in the text. I listed the code that i hav
made so far. Could somebody tell me what is wrong with my code.

Sub Count_Gate()

Dim Gate1 As Integer
Dim Gate2 As Integer
Dim Gate4 As Integer

Gate1 = 0
Gate2 = 0
Gate4 = 0

Do
If Columns("B:B") = "Gate 1" Then
Gate1 = Gate1 + 1
End If

Loop Until Range("B:B").End(xlUp).Row

Thank you

Morr

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Search for text in a cell

You can use COUNTIF for this:

Sub TestIt()
Dim SearchString As String

SearchString = "Gate 4"

MsgBox Application.CountIf(Range("B:B"), "*" & SearchString & "*")
End Sub

--
Regards

Juan Pablo González

"morry " wrote in message
...
In column B of my spreadsheet i have descriptions that are about twenty
or so words long. I want to count the one's that contain specific text
such as "Gate 4" contained in the text. I listed the code that i have
made so far. Could somebody tell me what is wrong with my code.

Sub Count_Gate()

Dim Gate1 As Integer
Dim Gate2 As Integer
Dim Gate4 As Integer

Gate1 = 0
Gate2 = 0
Gate4 = 0

Do
If Columns("B:B") = "Gate 1" Then
Gate1 = Gate1 + 1
End If

Loop Until Range("B:B").End(xlUp).Row

Thank you

Morry


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Search for text in a cell

Your code looks for the entire cell being the searched value, try:

Sub Count_Gate()

Dim r As Range
Dim Gate1 As Integer
Dim Gate2 As Integer
Dim Gate4 As Integer

Gate1 = 0
Gate2 = 0
Gate4 = 0

For Each r in Range("B1:B" & Range("B65536").End(xlUp).Row)
If Instr(1, r.Value, "Gate 1") < 0 Then Gate1 = Gate1 + 1
Next

End Sub



--
Message posted from http://www.ExcelForum.com

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
FIND / SEARCH text compare cell to string in 3rd cell nastech Excel Discussion (Misc queries) 0 October 29th 07 02:51 AM
Search text in a cell J@Y Excel Discussion (Misc queries) 4 June 14th 07 10:50 PM
How to search for text within a cell? Eric Excel Discussion (Misc queries) 9 May 13th 07 04:30 PM
Search text within cell [email protected] Excel Worksheet Functions 2 July 21st 06 02:17 PM
How do I search for specific text and sum the cell to the right? PacRat2001 Excel Worksheet Functions 3 October 12th 05 04:21 AM


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