ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variable Command for VBA in Excel (https://www.excelbanter.com/excel-programming/413857-variable-command-vba-excel.html)

IBT Employee

Variable Command for VBA in Excel
 
Good Morning Everyone,

I have a question for you VBA Experts out there. I'm trying to organize data
through color coding using the "For Each" loop, and I'm wondering if there is
a command that can define a variable?

For Example, a product number we have is D0000200, but there is another
product number that is D00002001. Both of these products are in the same
group, despite having different numbers.

I'm wondering if VBA can discriminate (or if there is a code that can act as
a variable, such as X in a simple math problem) the "D0000" portion of the
code and look expressly at the "200" or "2001" expression?

Any help is greatly appreciated!!!

~Fernando, IBT Employee


Bob Phillips[_3_]

Variable Command for VBA in Excel
 
Maybe something like this

Select Case Left$(myVariable, 5)

Case "D0000"

Select Case Right(Mid$(myVariable, 6, Len(myVariable) - 5)

Case "200"
'do something

Case "2001"
'do something else

'etc.
End Select

'etc.
End Select

--
__________________________________
HTH

Bob

"IBT Employee" <IBT wrote in message
...
Good Morning Everyone,

I have a question for you VBA Experts out there. I'm trying to organize
data
through color coding using the "For Each" loop, and I'm wondering if there
is
a command that can define a variable?

For Example, a product number we have is D0000200, but there is another
product number that is D00002001. Both of these products are in the same
group, despite having different numbers.

I'm wondering if VBA can discriminate (or if there is a code that can act
as
a variable, such as X in a simple math problem) the "D0000" portion of the
code and look expressly at the "200" or "2001" expression?

Any help is greatly appreciated!!!

~Fernando, IBT Employee




StumpedAgain

Variable Command for VBA in Excel
 
You can certainly write something that says

If ActiveCell = "*2001" then blah blah
else if Active Cell = "*200" then blah blah
end if

If you define the cell that you're looking at as CurrentProduct then you
could do something similar such as:

If CurrentProduct.Value like "*2001" then blah blah
else if CurrentProduct.Value like "*200" then blah blah
end if

The "*" is a wild card and accounts for anything.

Is this what you're looking for?

"IBT Employee" wrote:

Good Morning Everyone,

I have a question for you VBA Experts out there. I'm trying to organize data
through color coding using the "For Each" loop, and I'm wondering if there is
a command that can define a variable?

For Example, a product number we have is D0000200, but there is another
product number that is D00002001. Both of these products are in the same
group, despite having different numbers.

I'm wondering if VBA can discriminate (or if there is a code that can act as
a variable, such as X in a simple math problem) the "D0000" portion of the
code and look expressly at the "200" or "2001" expression?

Any help is greatly appreciated!!!

~Fernando, IBT Employee


IBT Employee[_2_]

Variable Command for VBA in Excel
 
Thank you, this is exactly what I was looking for!

"Bob Phillips" wrote:

Maybe something like this

Select Case Left$(myVariable, 5)

Case "D0000"

Select Case Right(Mid$(myVariable, 6, Len(myVariable) - 5)

Case "200"
'do something

Case "2001"
'do something else

'etc.
End Select

'etc.
End Select

--
__________________________________
HTH

Bob

"IBT Employee" <IBT wrote in message
...
Good Morning Everyone,

I have a question for you VBA Experts out there. I'm trying to organize
data
through color coding using the "For Each" loop, and I'm wondering if there
is
a command that can define a variable?

For Example, a product number we have is D0000200, but there is another
product number that is D00002001. Both of these products are in the same
group, despite having different numbers.

I'm wondering if VBA can discriminate (or if there is a code that can act
as
a variable, such as X in a simple math problem) the "D0000" portion of the
code and look expressly at the "200" or "2001" expression?

Any help is greatly appreciated!!!

~Fernando, IBT Employee





IBT Employee[_2_]

Variable Command for VBA in Excel
 
Yes thank you, both of these replies have clarified the situation greatly.

"StumpedAgain" wrote:

You can certainly write something that says

If ActiveCell = "*2001" then blah blah
else if Active Cell = "*200" then blah blah
end if

If you define the cell that you're looking at as CurrentProduct then you
could do something similar such as:

If CurrentProduct.Value like "*2001" then blah blah
else if CurrentProduct.Value like "*200" then blah blah
end if

The "*" is a wild card and accounts for anything.

Is this what you're looking for?

"IBT Employee" wrote:

Good Morning Everyone,

I have a question for you VBA Experts out there. I'm trying to organize data
through color coding using the "For Each" loop, and I'm wondering if there is
a command that can define a variable?

For Example, a product number we have is D0000200, but there is another
product number that is D00002001. Both of these products are in the same
group, despite having different numbers.

I'm wondering if VBA can discriminate (or if there is a code that can act as
a variable, such as X in a simple math problem) the "D0000" portion of the
code and look expressly at the "200" or "2001" expression?

Any help is greatly appreciated!!!

~Fernando, IBT Employee



All times are GMT +1. The time now is 09:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com