Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default String variable name is incorrectly used literally

I have the following autofilter statement in my macro:

Selection.AutoFilter Field:=1, Criteria1:="=*SKU*", Operator:=xlAnd

The term "SKU" in this statment is Dimensioned as a string variable
but it is being used literally. That is the autofilter is selecting
lines that contain SKU.

How do I get this autofilter statement to understand SKU is a string
variable?

Thank you.


John Keith

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default String variable name is incorrectly used literally

Do you need SKU dimensioned as a string variable someplace else? If so, I
think I'd change it so that it's mySKU or something like that so that you
know it's the variable.
--
HTH,
Barb Reinhardt




"John Keith" wrote:

I have the following autofilter statement in my macro:

Selection.AutoFilter Field:=1, Criteria1:="=*SKU*", Operator:=xlAnd

The term "SKU" in this statment is Dimensioned as a string variable
but it is being used literally. That is the autofilter is selecting
lines that contain SKU.

How do I get this autofilter statement to understand SKU is a string
variable?

Thank you.


John Keith


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default String variable name is incorrectly used literally

On Sun, 14 Sep 2008 06:07:01 -0700, Barb Reinhardt
wrote:

Do you need SKU dimensioned as a string variable someplace else? If so, I
think I'd change it so that it's mySKU or something like that so that you
know it's the variable.


Barb,

Wow! What a quick response.

I do use the variable one other time, but I can eaily change the name.

But changing the variable name does not solve the problem, the
autofilter now thinks it is searching for mySKU.


John Keith

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default String variable name is incorrectly used literally

This works with me:

Selection.AutoFilter Field:=1, Criteria1:=SKU, Operator:=xlAnd


RBS


"John Keith" wrote in message
...
I have the following autofilter statement in my macro:

Selection.AutoFilter Field:=1, Criteria1:="=*SKU*", Operator:=xlAnd

The term "SKU" in this statment is Dimensioned as a string variable
but it is being used literally. That is the autofilter is selecting
lines that contain SKU.

How do I get this autofilter statement to understand SKU is a string
variable?

Thank you.


John Keith


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default String variable name is incorrectly used literally

In this line, you are searching for somethng that contains SKU. Don't
change this one.

Selection.AutoFilter Field:=1, Criteria1:="=*SKU*", Operator:=xlAnd

If you refer to SKU someplace else, use mySKU or something so that it knows
they are different.
--
HTH,
Barb Reinhardt




"RB Smissaert" wrote:

This works with me:

Selection.AutoFilter Field:=1, Criteria1:=SKU, Operator:=xlAnd


RBS


"John Keith" wrote in message
...
I have the following autofilter statement in my macro:

Selection.AutoFilter Field:=1, Criteria1:="=*SKU*", Operator:=xlAnd

The term "SKU" in this statment is Dimensioned as a string variable
but it is being used literally. That is the autofilter is selecting
lines that contain SKU.

How do I get this autofilter statement to understand SKU is a string
variable?

Thank you.


John Keith





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default String variable name is incorrectly used literally

On Sun, 14 Sep 2008 11:51:01 -0700, Barb Reinhardt
wrote:

In this line, you are searching for somethng that contains SKU. Don't
change this one.

Selection.AutoFilter Field:=1, Criteria1:="=*SKU*", Operator:=xlAnd

If you refer to SKU someplace else, use mySKU or something so that it knows
they are different.



Barb,

Thanks for following up, but the above command is still interpreting
"SKU" as the item I am trying to filter on rather than the value of
'SKU". (This line is at the end of my macro right now, and when I go
to check the filter settings it says it was looking for rows that
contains "SKU" in the first column.

But I'm confused about something else. The string "SKU" never appears
in the column I am filtering but all of my original rows still are
visible, so it's as if no filtering was done.

I'm still confused.


John Keith

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default String variable name is incorrectly used literally

On Sun, 14 Sep 2008 14:10:32 +0100, "RB Smissaert"
wrote:

This works with me:

Selection.AutoFilter Field:=1, Criteria1:=SKU, Operator:=xlAnd


In this case the filter does recognize "SKU" as a variable but this
criteria is for if the cell equals the value of SKU. I need the
criteria to be contains the value of "SKU". That is why my first post
had the asterisk on either side of "SKU".

Any one else have a suggestion?



John Keith

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default String variable name is incorrectly used literally

Ah, yes, didn't read it properly.

RBS


"John Keith" wrote in message
...
On Sun, 14 Sep 2008 14:10:32 +0100, "RB Smissaert"
wrote:

This works with me:

Selection.AutoFilter Field:=1, Criteria1:=SKU, Operator:=xlAnd


In this case the filter does recognize "SKU" as a variable but this
criteria is for if the cell equals the value of SKU. I need the
criteria to be contains the value of "SKU". That is why my first post
had the asterisk on either side of "SKU".

Any one else have a suggestion?



John Keith


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default String variable name is incorrectly used literally

Now that I think about this, I'm wondering if you are trying to find cells
that are equal to whatever is in your variable SKU. Can you clarify what you
want.

Barb Reinhardt




"John Keith" wrote:

I have the following autofilter statement in my macro:

Selection.AutoFilter Field:=1, Criteria1:="=*SKU*", Operator:=xlAnd

The term "SKU" in this statment is Dimensioned as a string variable
but it is being used literally. That is the autofilter is selecting
lines that contain SKU.

How do I get this autofilter statement to understand SKU is a string
variable?

Thank you.


John Keith


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default String variable name is incorrectly used literally

On Sun, 14 Sep 2008 12:02:01 -0700, Barb Reinhardt
wrote:

Now that I think about this, I'm wondering if you are trying to find cells
that are equal to whatever is in your variable SKU. Can you clarify what you
want.


Barb,

Yes, I am trying to find rows that contain the value of the variable
SKU.



John Keith



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default String variable name is incorrectly used literally

try Criteria1:="=*" & SKU & "*",

--


Gary


"John Keith" wrote in message
...
On Sun, 14 Sep 2008 12:02:01 -0700, Barb Reinhardt
wrote:

Now that I think about this, I'm wondering if you are trying to find cells
that are equal to whatever is in your variable SKU. Can you clarify what you
want.


Barb,

Yes, I am trying to find rows that contain the value of the variable
SKU.



John Keith



  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default String variable name is incorrectly used literally

On Sun, 14 Sep 2008 15:31:45 -0400, "Gary Keramidas"
<GKeramidasATmsn.com wrote:

try Criteria1:="=*" & SKU & "*",


Gary,

The autofilter settings now reflect the contents of the string
variable so that is a big step forward. (Thanks, how does one figure
out the correct syntax for somethig like this????)

But...... as noted in in another reply from me the filter does not
appear to be working as all the original rows still appear. I'll go
experiment so more but if anyone else has a suggestion I'm all ears.



John Keith

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default String variable name is incorrectly used literally

Recording a macro showed me the right syntax:

Sub test()

Dim str As String

str = "g"

Selection.AutoFilter Field:=1, Criteria1:="=**" & str & "**"

End Sub


RBS


"John Keith" wrote in message
...
On Sun, 14 Sep 2008 15:31:45 -0400, "Gary Keramidas"
<GKeramidasATmsn.com wrote:

try Criteria1:="=*" & SKU & "*",


Gary,

The autofilter settings now reflect the contents of the string
variable so that is a big step forward. (Thanks, how does one figure
out the correct syntax for somethig like this????)

But...... as noted in in another reply from me the filter does not
appear to be working as all the original rows still appear. I'll go
experiment so more but if anyone else has a suggestion I'm all ears.



John Keith


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default String variable name is incorrectly used literally

On Sun, 14 Sep 2008 14:12:50 -0600, John Keith wrote:

But...... as noted in in another reply from me the filter does not
appear to be working as all the original rows still appear. I'll go
experiment so more but if anyone else has a suggestion I'm all ears.


The filter is not working even when I manually go through the process
so something else is clearly going on.

Thanks for all the suggestions.

John Keith

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
Trying To Append String Variable To Another String Variable Joe K. Excel Programming 3 October 6th 07 02:11 AM
Im literally a beginner, please help! genuinegal via OfficeKB.com Excel Programming 1 October 10th 05 12:10 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Literally - every other time Steph[_3_] Excel Programming 0 June 9th 04 08:50 PM
How do I convert an integer variable to a string variable? dumbass Excel Programming 2 May 21st 04 07:34 PM


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