A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VBA Wildcard Code



 
 
Thread Tools Display Modes
  #1  
Old May 15th, 2009, 02:55 PM posted to microsoft.public.excel.misc
Tony
external usenet poster
 
Posts: 593
Default VBA Wildcard Code

I have the following could that checks a column in a master file to select
records that have the following c* (i.e. c01, c02, etc..). However due to
some error in the way I am writing the code, I cannot get it to produce
records.


If wsMaster.Range("ag" & iRow + 0) = "c* " Then

How do I code it the slect any records that start with "C" and then use the
wildcard character "*"?

  #2  
Old May 15th, 2009, 03:01 PM posted to microsoft.public.excel.misc
Gary''s Student
external usenet poster
 
Posts: 7,584
Default VBA Wildcard Code

If Left(wsMaster.Range("ag" & iRow + 0),1) = "c" Then
--
Gary''s Student - gsnu200853


"Tony" wrote:

I have the following could that checks a column in a master file to select
records that have the following c* (i.e. c01, c02, etc..). However due to
some error in the way I am writing the code, I cannot get it to produce
records.


If wsMaster.Range("ag" & iRow + 0) = "c* " Then

How do I code it the slect any records that start with "C" and then use the
wildcard character "*"?

  #3  
Old May 15th, 2009, 03:04 PM posted to microsoft.public.excel.misc
Mike H
external usenet poster
 
Posts: 8,419
Default VBA Wildcard Code

Try instr

If InStr(Sheets(wsMaster).Range("ag" & irow + 0), "c") = 1 Then

Mike

"Tony" wrote:

I have the following could that checks a column in a master file to select
records that have the following c* (i.e. c01, c02, etc..). However due to
some error in the way I am writing the code, I cannot get it to produce
records.


If wsMaster.Range("ag" & iRow + 0) = "c* " Then

How do I code it the slect any records that start with "C" and then use the
wildcard character "*"?

  #4  
Old May 15th, 2009, 03:06 PM posted to microsoft.public.excel.misc
Mike H
external usenet poster
 
Posts: 8,419
Default VBA Wildcard Code

I just noticed you may want it to ignore case

If InStr(1, Sheets(wsMaster).Range("ag" & irow + 0), "c", 1) = 1 Then

Mike

"Mike H" wrote:

Try instr

If InStr(Sheets(wsMaster).Range("ag" & irow + 0), "c") = 1 Then

Mike

"Tony" wrote:

I have the following could that checks a column in a master file to select
records that have the following c* (i.e. c01, c02, etc..). However due to
some error in the way I am writing the code, I cannot get it to produce
records.


If wsMaster.Range("ag" & iRow + 0) = "c* " Then

How do I code it the slect any records that start with "C" and then use the
wildcard character "*"?

  #5  
Old May 15th, 2009, 03:15 PM posted to microsoft.public.excel.misc
Tony
external usenet poster
 
Posts: 593
Default VBA Wildcard Code

Gary, even though I checked the running of the code and verified that the
cell contents does contain a Cxx value after reading each record, it bypasses
the record
and moves on the to the next record with the final outcome being no records
written.

Any suggestions?

Tony

"Gary''s Student" wrote:

If Left(wsMaster.Range("ag" & iRow + 0),1) = "c" Then
--
Gary''s Student - gsnu200853


"Tony" wrote:

I have the following could that checks a column in a master file to select
records that have the following c* (i.e. c01, c02, etc..). However due to
some error in the way I am writing the code, I cannot get it to produce
records.


If wsMaster.Range("ag" & iRow + 0) = "c* " Then

How do I code it the slect any records that start with "C" and then use the
wildcard character "*"?

  #6  
Old May 15th, 2009, 03:17 PM posted to microsoft.public.excel.misc
Tony
external usenet poster
 
Posts: 593
Default VBA Wildcard Code

Mike, when I use your code, I get a Run-time error '13' - Type mismatch error.

"Mike H" wrote:

I just noticed you may want it to ignore case

If InStr(1, Sheets(wsMaster).Range("ag" & irow + 0), "c", 1) = 1 Then

Mike

"Mike H" wrote:

Try instr

If InStr(Sheets(wsMaster).Range("ag" & irow + 0), "c") = 1 Then

Mike

"Tony" wrote:

I have the following could that checks a column in a master file to select
records that have the following c* (i.e. c01, c02, etc..). However due to
some error in the way I am writing the code, I cannot get it to produce
records.


If wsMaster.Range("ag" & iRow + 0) = "c* " Then

How do I code it the slect any records that start with "C" and then use the
wildcard character "*"?

  #7  
Old May 15th, 2009, 03:18 PM posted to microsoft.public.excel.misc
Dave Peterson
external usenet poster
 
Posts: 19,791
Default VBA Wildcard Code

One more using a wildcard:

if lcase(wsmaster.range("ag" & irow).value) like lcase("c*") then




Tony wrote:

I have the following could that checks a column in a master file to select
records that have the following c* (i.e. c01, c02, etc..). However due to
some error in the way I am writing the code, I cannot get it to produce
records.

If wsMaster.Range("ag" & iRow + 0) = "c* " Then

How do I code it the slect any records that start with "C" and then use the
wildcard character "*"?


--

Dave Peterson
  #8  
Old May 15th, 2009, 03:21 PM posted to microsoft.public.excel.misc
Gary''s Student
external usenet poster
 
Posts: 7,584
Default VBA Wildcard Code

Try both "c" and "C"
--
Gary''s Student - gsnu200853


"Tony" wrote:

Gary, even though I checked the running of the code and verified that the
cell contents does contain a Cxx value after reading each record, it bypasses
the record
and moves on the to the next record with the final outcome being no records
written.

Any suggestions?

Tony

"Gary''s Student" wrote:

If Left(wsMaster.Range("ag" & iRow + 0),1) = "c" Then
--
Gary''s Student - gsnu200853


"Tony" wrote:

I have the following could that checks a column in a master file to select
records that have the following c* (i.e. c01, c02, etc..). However due to
some error in the way I am writing the code, I cannot get it to produce
records.


If wsMaster.Range("ag" & iRow + 0) = "c* " Then

How do I code it the slect any records that start with "C" and then use the
wildcard character "*"?

  #9  
Old May 15th, 2009, 03:34 PM posted to microsoft.public.excel.misc
Tony
external usenet poster
 
Posts: 593
Default VBA Wildcard Code

Thanks again Dave, that did the trick.

"Dave Peterson" wrote:

One more using a wildcard:

if lcase(wsmaster.range("ag" & irow).value) like lcase("c*") then




Tony wrote:

I have the following could that checks a column in a master file to select
records that have the following c* (i.e. c01, c02, etc..). However due to
some error in the way I am writing the code, I cannot get it to produce
records.

If wsMaster.Range("ag" & iRow + 0) = "c* " Then

How do I code it the slect any records that start with "C" and then use the
wildcard character "*"?


--

Dave Peterson

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:08 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.