Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Wildcard in Excel VBA

I'm trying to use a search box in excel vba with a wildcard. My sheet
list about 1000 employees with among other things there job title.
What I'd to do is have the search box use a wildcard to search and
then delete those that do not match. The code I have so far is:

Sub DeleteRows()
Dim JobTitle, FinDate As Date, LastRow&, i&
MsgBox ("Use this routine will DELETE many rows in your Excel Sheet,
proceed with CAUTION!!")
JobTitle = InputBox("Enter Job Title Below - Caution ROWS will be
deleted!!!!!")
LastRow = Cells(Rows.Count, 12).End(xlUp).Row
For i = LastRow To 2 Step -1
If Cells(i, 12).Value < JobTitle & "*" Then
Rows(i).Delete
End If
Next i
End Sub

An example of a job title would be: Branch Manager, Branch Manager I,
Branch Manager II and so on. I would like enter: 'Branch' (without
the quote marks of course) and have all those job titles that start
with Branch remain while the other rows get deleted. As is, all rows
get deleted. Any ideas?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Wildcard in Excel VBA

On May 30, 11:13 am, JE McGimpsey wrote:
One way:

If Cells(i, 12).Text Like JobTitle & "*" Then

In article . com,



wrote:
I'm trying to use a search box in excel vba with a wildcard. My sheet
list about 1000 employees with among other things there job title.
What I'd to do is have the search box use a wildcard to search and
then delete those that do not match. The code I have so far is:


Sub DeleteRows()
Dim JobTitle, FinDate As Date, LastRow&, i&
MsgBox ("Use this routine will DELETE many rows in your Excel Sheet,
proceed with CAUTION!!")
JobTitle = InputBox("Enter Job Title Below - Caution ROWS will be
deleted!!!!!")
LastRow = Cells(Rows.Count, 12).End(xlUp).Row
For i = LastRow To 2 Step -1
If Cells(i, 12).Value < JobTitle & "*" Then
Rows(i).Delete
End If
Next i
End Sub


An example of a job title would be: Branch Manager, Branch Manager I,
Branch Manager II and so on. I would like enter: 'Branch' (without
the quote marks of course) and have all those job titles that start
with Branch remain while the other rows get deleted. As is, all rows
get deleted. Any ideas?- Hide quoted text -


- Show quoted text -


Thanks for the quick repsone JE, however your suggestion deletes the
rows I want to keep. I want to do the reverse. I've tried modifing
what you suggested to:

if cells(i,12).text LIKE NOT JobTitle & "*" Then....but the error
message I get is Type MisMatch...any ideas?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Wildcard in Excel VBA

On May 30, 11:33 am, wrote:
On May 30, 11:13 am, JE McGimpsey wrote:





One way:


If Cells(i, 12).Text Like JobTitle & "*" Then


In article . com,


wrote:
I'm trying to use a search box in excel vba with a wildcard. My sheet
list about 1000 employees with among other things there job title.
What I'd to do is have the search box use a wildcard to search and
then delete those that do not match. The code I have so far is:


Sub DeleteRows()
Dim JobTitle, FinDate As Date, LastRow&, i&
MsgBox ("Use this routine will DELETE many rows in your Excel Sheet,
proceed with CAUTION!!")
JobTitle = InputBox("Enter Job Title Below - Caution ROWS will be
deleted!!!!!")
LastRow = Cells(Rows.Count, 12).End(xlUp).Row
For i = LastRow To 2 Step -1
If Cells(i, 12).Value < JobTitle & "*" Then
Rows(i).Delete
End If
Next i
End Sub


An example of a job title would be: Branch Manager, Branch Manager I,
Branch Manager II and so on. I would like enter: 'Branch' (without
the quote marks of course) and have all those job titles that start
with Branch remain while the other rows get deleted. As is, all rows
get deleted. Any ideas?- Hide quoted text -


- Show quoted text -


Thanks for the quick repsone JE, however your suggestion deletes the
rows I want to keep. I want to do the reverse. I've tried modifing
what you suggested to:

if cells(i,12).text LIKE NOT JobTitle & "*" Then....but the error
message I get is Type MisMatch...any ideas?- Hide quoted text -

- Show quoted text -


Thanks to all...Jeol, I tried your suggestion and that seems to
work ...thanks again....

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Wildcard in Excel VBA

I guess you can count on your users to enter the Job title with the exact
capitalization. If not, you might want to account for that.

? Left("Branch Manager",len("branch")) = "branch"
False
? Left("Branch Manager",len("Branch")) = "Branch"
True



--
Regards,
Tom Ogilvy


" wrote:

On May 30, 11:33 am, wrote:
On May 30, 11:13 am, JE McGimpsey wrote:





One way:


If Cells(i, 12).Text Like JobTitle & "*" Then


In article . com,


wrote:
I'm trying to use a search box in excel vba with a wildcard. My sheet
list about 1000 employees with among other things there job title.
What I'd to do is have the search box use a wildcard to search and
then delete those that do not match. The code I have so far is:


Sub DeleteRows()
Dim JobTitle, FinDate As Date, LastRow&, i&
MsgBox ("Use this routine will DELETE many rows in your Excel Sheet,
proceed with CAUTION!!")
JobTitle = InputBox("Enter Job Title Below - Caution ROWS will be
deleted!!!!!")
LastRow = Cells(Rows.Count, 12).End(xlUp).Row
For i = LastRow To 2 Step -1
If Cells(i, 12).Value < JobTitle & "*" Then
Rows(i).Delete
End If
Next i
End Sub


An example of a job title would be: Branch Manager, Branch Manager I,
Branch Manager II and so on. I would like enter: 'Branch' (without
the quote marks of course) and have all those job titles that start
with Branch remain while the other rows get deleted. As is, all rows
get deleted. Any ideas?- Hide quoted text -


- Show quoted text -


Thanks for the quick repsone JE, however your suggestion deletes the
rows I want to keep. I want to do the reverse. I've tried modifing
what you suggested to:

if cells(i,12).text LIKE NOT JobTitle & "*" Then....but the error
message I get is Type MisMatch...any ideas?- Hide quoted text -

- Show quoted text -


Thanks to all...Jeol, I tried your suggestion and that seems to
work ...thanks again....




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Wildcard in Excel VBA

Could head a module dedicated for such string comparisons -

Option Compare Text

Regards,
Peter T

"Tom Ogilvy" wrote in message
...
I guess you can count on your users to enter the Job title with the exact
capitalization. If not, you might want to account for that.

? Left("Branch Manager",len("branch")) = "branch"
False
? Left("Branch Manager",len("Branch")) = "Branch"
True



--
Regards,
Tom Ogilvy


" wrote:

On May 30, 11:33 am, wrote:
On May 30, 11:13 am, JE McGimpsey wrote:





One way:

If Cells(i, 12).Text Like JobTitle & "*" Then

In article . com,

wrote:
I'm trying to use a search box in excel vba with a wildcard. My

sheet
list about 1000 employees with among other things there job title.
What I'd to do is have the search box use a wildcard to search and
then delete those that do not match. The code I have so far is:

Sub DeleteRows()
Dim JobTitle, FinDate As Date, LastRow&, i&
MsgBox ("Use this routine will DELETE many rows in your Excel

Sheet,
proceed with CAUTION!!")
JobTitle = InputBox("Enter Job Title Below - Caution ROWS will

be
deleted!!!!!")
LastRow = Cells(Rows.Count, 12).End(xlUp).Row
For i = LastRow To 2 Step -1
If Cells(i, 12).Value < JobTitle & "*" Then
Rows(i).Delete
End If
Next i
End Sub

An example of a job title would be: Branch Manager, Branch Manager

I,
Branch Manager II and so on. I would like enter: 'Branch'

(without
the quote marks of course) and have all those job titles that

start
with Branch remain while the other rows get deleted. As is, all

rows
get deleted. Any ideas?- Hide quoted text -

- Show quoted text -

Thanks for the quick repsone JE, however your suggestion deletes the
rows I want to keep. I want to do the reverse. I've tried modifing
what you suggested to:

if cells(i,12).text LIKE NOT JobTitle & "*" Then....but the error
message I get is Type MisMatch...any ideas?- Hide quoted text -

- Show quoted text -


Thanks to all...Jeol, I tried your suggestion and that seems to
work ...thanks again....




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Wildcard in Excel VBA

try changing this line
from
If Cells(i, 12).Value < JobTitle & "*" then
to
If left(Cells(i, 12).Value,len(JobTitle) < JobTitle Then

" wrote:

I'm trying to use a search box in excel vba with a wildcard. My sheet
list about 1000 employees with among other things there job title.
What I'd to do is have the search box use a wildcard to search and
then delete those that do not match. The code I have so far is:

Sub DeleteRows()
Dim JobTitle, FinDate As Date, LastRow&, i&
MsgBox ("Use this routine will DELETE many rows in your Excel Sheet,
proceed with CAUTION!!")
JobTitle = InputBox("Enter Job Title Below - Caution ROWS will be
deleted!!!!!")
LastRow = Cells(Rows.Count, 12).End(xlUp).Row
For i = LastRow To 2 Step -1
If Cells(i, 12).Value < JobTitle & "*" Then
Rows(i).Delete
End If
Next i
End Sub

An example of a job title would be: Branch Manager, Branch Manager I,
Branch Manager II and so on. I would like enter: 'Branch' (without
the quote marks of course) and have all those job titles that start
with Branch remain while the other rows get deleted. As is, all rows
get deleted. Any ideas?


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Wildcard in Excel VBA

Modified to delete everything except LIKE Branch....

Mike

Sub DeleteRows()
Dim JobTitle, FinDate As Date
MsgBox ("Use this routine will DELETE many rows in your Excel Sheet,proceed
with CAUTION!!")
JobTitle = InputBox("Enter Job Title Below - Caution ROWS will be
deleted!!!!!")
LastRow = ActiveSheet.Range("L65536").End(xlUp).Row
For i = LastRow To 2 Step -1
If Cells(i, 12).Value Like JobTitle & "*" Then

Else
Rows(i).Delete
End If

Next i
End Sub

" wrote:

I'm trying to use a search box in excel vba with a wildcard. My sheet
list about 1000 employees with among other things there job title.
What I'd to do is have the search box use a wildcard to search and
then delete those that do not match. The code I have so far is:

Sub DeleteRows()
Dim JobTitle, FinDate As Date, LastRow&, i&
MsgBox ("Use this routine will DELETE many rows in your Excel Sheet,
proceed with CAUTION!!")
JobTitle = InputBox("Enter Job Title Below - Caution ROWS will be
deleted!!!!!")
LastRow = Cells(Rows.Count, 12).End(xlUp).Row
For i = LastRow To 2 Step -1
If Cells(i, 12).Value < JobTitle & "*" Then
Rows(i).Delete
End If
Next i
End Sub

An example of a job title would be: Branch Manager, Branch Manager I,
Branch Manager II and so on. I would like enter: 'Branch' (without
the quote marks of course) and have all those job titles that start
with Branch remain while the other rows get deleted. As is, all rows
get deleted. Any ideas?


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
How do I use a wildcard in an excel formula? Archon007 Excel Worksheet Functions 4 March 16th 07 07:16 AM
Wildcard in Excel Clark Shiao Excel Worksheet Functions 4 November 20th 06 01:27 PM
How can I get Excel to not view an * as a wildcard in a lookup? Misty Excel Discussion (Misc queries) 1 March 3rd 06 08:01 PM
Wildcard parameter in excel BJC Excel Discussion (Misc queries) 1 December 24th 04 12:16 PM
Activate an Excel spreadsheet using wildcard name Dennis Excel Programming 1 September 9th 04 01:44 AM


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