Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default InStr Function Question


I am trying to use the InStr function to determine if a text string i
contained within a cell, then delete the entire row if it is not found
move down 1 row, and loop until a blank cell is encountered.

It looks as if the syntax requires the text to be typed in the string
field, but I have different text in each cell that I want the functio
to run on.

InStr([start, ]string1, string2[, compare])

Can I put a range for string1

--
gfh2810
-----------------------------------------------------------------------
gfh28105's Profile: http://www.excelforum.com/member.php...fo&userid=2722
View this thread: http://www.excelforum.com/showthread.php?threadid=46735

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default InStr Function Question

Hi GFH,

Sub Tester02()
Dim Pos As Long

ActiveCell.Value = "Big Ben"
pos = InStr(1, ActiveCell.Value, "Ben", vbTextCompare)
MsgBox Pos

End Sub


---
Regards,
Norman



"gfh28105" wrote in
message ...

I am trying to use the InStr function to determine if a text string is
contained within a cell, then delete the entire row if it is not found,
move down 1 row, and loop until a blank cell is encountered.

It looks as if the syntax requires the text to be typed in the string1
field, but I have different text in each cell that I want the function
to run on.

InStr([start, ]string1, string2[, compare])

Can I put a range for string1?


--
gfh28105
------------------------------------------------------------------------
gfh28105's Profile:
http://www.excelforum.com/member.php...o&userid=27223
View this thread: http://www.excelforum.com/showthread...hreadid=467359



  #3   Report Post  
Posted to microsoft.public.excel.programming
A C A C is offline
external usenet poster
 
Posts: 8
Default InStr Function Question


"gfh28105" wrote in
message ...

I am trying to use the InStr function to determine if a text string is
contained within a cell, then delete the entire row if it is not found,
move down 1 row, and loop until a blank cell is encountered.

It looks as if the syntax requires the text to be typed in the string1
field, but I have different text in each cell that I want the function
to run on.

InStr([start, ]string1, string2[, compare])

Can I put a range for string1?


Just use the <cell.Value to get the string in the cell. Post back your
looping code so we can see how you are getting to the cell in question and
we can be more precise about the syntax. As an interim I have posted below
some simple demo code which may be enough to help you. Note that if you
delete a row you need to be careful about moving to the next row as that is
now the *next* row...

Sub DeleteRows()

dim strSearch as string
strSearch = "b" 'search for any cell with the letter b in it

Range("A1").Activate
While ActiveCell.Value < ""
If InStr(ActiveCell.Value, strSearch) Then
ActiveCell.EntireRow.Delete
Else
ActiveCell.Offset(1).Activate
End If
Wend


End Sub

Hope this helps
A


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default InStr Function Question

Altough you could use the AutoFilter to do this in a much faster way, using
InStr would be something like

If InStr(1, Cells(i, 1).Value, "test") 0 Then
'The cell has the text
End If

Where i is the counter that you're using (if you are). In that case, it
would look at column A.

But again, try recording a macro using an Autofilter, with "Custom", and
then "Contains" and your text.

--
Regards,

Juan Pablo González
Excel MVP

"gfh28105" wrote in
message ...

I am trying to use the InStr function to determine if a text string is
contained within a cell, then delete the entire row if it is not found,
move down 1 row, and loop until a blank cell is encountered.

It looks as if the syntax requires the text to be typed in the string1
field, but I have different text in each cell that I want the function
to run on.

InStr([start, ]string1, string2[, compare])

Can I put a range for string1?


--
gfh28105
------------------------------------------------------------------------
gfh28105's Profile:
http://www.excelforum.com/member.php...o&userid=27223
View this thread: http://www.excelforum.com/showthread...hreadid=467359



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
Use InStr function in formula? Lee Hunter Excel Worksheet Functions 8 May 8th 23 03:45 AM
Help with VBA InStr() function EagleOne Excel Discussion (Misc queries) 10 April 12th 07 02:47 PM
Where is the Instr() function in Excel 2003? chem21 Excel Discussion (Misc queries) 3 October 9th 06 03:49 PM
InStr function question [email protected] Excel Programming 9 June 28th 05 03:03 PM
Instr function problem Ross Withey Excel Programming 9 November 14th 03 08:02 AM


All times are GMT +1. The time now is 05:35 AM.

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"