Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default If Statement with multiple qualifiers


Hopefully my title is somewhat descriptive of my question. I have one
column (B) of text data. I want to write a macro that will go down
this column and look at the text one row at a time. Depending on what
the cell's content is, it will then assign a number to the adjacent
column (C). My macro works fine as long as I only have one qualifier
in my If statement. For example, my activecell is the empty column
that I want to assign the number to.

This will work:
Do
If ActiveCell.Offset(0,-1) = "BALL" Then Activecell = 3
ElseIf ActiveCell.Offset(0,-1) = "HAMMER" Then Activecell =
8
etc.
EndIf
ActiveCell.Offset(1,0).Activate
Loop Until....

What I want is:
Do
If ActiveCell.Offset(0,-1) = "BALL" Or "MOUSE" Or "STAPLER" Then
Activecell = 3
ElseIf ActiveCell.Offset(0,-1) = "HAMMER" Or "PEN" Then
Activecell = 8
etc.
EndIf
ActiveCell.Offset(1,0).Activate
Loop Until....

The above gets a mismatch error. How do I arrange my possible options
to condense my code so that I don't have to have an elseif statement
for every single option? Thanks for any responses.


--
mworth01
------------------------------------------------------------------------
mworth01's Profile: http://www.excelforum.com/member.php...fo&userid=8991
View this thread: http://www.excelforum.com/showthread...hreadid=399472

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default If Statement with multiple qualifiers

Try this

Do
If ActiveCell.Offset(0,-1) = "BALL" Or ActiveCell.Offset(0,-1) = "MOUSE" Or
ActiveCell.Offset(0,-1) = "STAPLER" Then
Activecell = 3
ElseIf ActiveCell.Offset(0,-1) = "HAMMER" Or ActiveCell.Offset(0,-1) = "PEN"
Then
Activecell = 8
etc.
EndIf
ActiveCell.Offset(1,0).Activate
Loop Until....


--
HTH...

Jim Thomlinson


"mworth01" wrote:


Hopefully my title is somewhat descriptive of my question. I have one
column (B) of text data. I want to write a macro that will go down
this column and look at the text one row at a time. Depending on what
the cell's content is, it will then assign a number to the adjacent
column (C). My macro works fine as long as I only have one qualifier
in my If statement. For example, my activecell is the empty column
that I want to assign the number to.

This will work:
Do
If ActiveCell.Offset(0,-1) = "BALL" Then Activecell = 3
ElseIf ActiveCell.Offset(0,-1) = "HAMMER" Then Activecell =
8
etc.
EndIf
ActiveCell.Offset(1,0).Activate
Loop Until....

What I want is:
Do
If ActiveCell.Offset(0,-1) = "BALL" Or "MOUSE" Or "STAPLER" Then
Activecell = 3
ElseIf ActiveCell.Offset(0,-1) = "HAMMER" Or "PEN" Then
Activecell = 8
etc.
EndIf
ActiveCell.Offset(1,0).Activate
Loop Until....

The above gets a mismatch error. How do I arrange my possible options
to condense my code so that I don't have to have an elseif statement
for every single option? Thanks for any responses.


--
mworth01
------------------------------------------------------------------------
mworth01's Profile: http://www.excelforum.com/member.php...fo&userid=8991
View this thread: http://www.excelforum.com/showthread...hreadid=399472


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default If Statement with multiple qualifiers

Try this:

Do
If ActiveCell.Offset(0, -1).Value = "BALL" Or ActiveCell.Offset(0, -1).Value
= "MOUSE" Or ActiveCell.Offset(0, -1).Value = "STAPLER" Then
ActiveCell = 3
ElseIf ActiveCell.Offset(0, -1).value = "HAMMER" Or ActiveCell.Offset(0,
-1).value ="PEN" Then
ActiveCell = 8
End If



"mworth01" wrote:


Hopefully my title is somewhat descriptive of my question. I have one
column (B) of text data. I want to write a macro that will go down
this column and look at the text one row at a time. Depending on what
the cell's content is, it will then assign a number to the adjacent
column (C). My macro works fine as long as I only have one qualifier
in my If statement. For example, my activecell is the empty column
that I want to assign the number to.

This will work:
Do
If ActiveCell.Offset(0,-1) = "BALL" Then Activecell = 3
ElseIf ActiveCell.Offset(0,-1) = "HAMMER" Then Activecell =
8
etc.
EndIf
ActiveCell.Offset(1,0).Activate
Loop Until....

What I want is:
Do
If ActiveCell.Offset(0,-1) = "BALL" Or "MOUSE" Or "STAPLER" Then
Activecell = 3
ElseIf ActiveCell.Offset(0,-1) = "HAMMER" Or "PEN" Then
Activecell = 8
etc.
EndIf
ActiveCell.Offset(1,0).Activate
Loop Until....

The above gets a mismatch error. How do I arrange my possible options
to condense my code so that I don't have to have an elseif statement
for every single option? Thanks for any responses.


--
mworth01
------------------------------------------------------------------------
mworth01's Profile: http://www.excelforum.com/member.php...fo&userid=8991
View this thread: http://www.excelforum.com/showthread...hreadid=399472


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default If Statement with multiple qualifiers


I often found this kind of error. Try repeat you
"ActiveCell.Offset(0,-1) =" to other criteria too like below.

ActiveCell.Offset(0,-1) = "BALL" Or ActiveCell.Offset(0,-1) = "MOUSE
Or ActiveCell.Offset(0,-1) = "STAPLER

--
hidek
-----------------------------------------------------------------------
hideki's Profile: http://www.excelforum.com/member.php...fo&userid=1890
View this thread: http://www.excelforum.com/showthread.php?threadid=39947

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
Text Qualifiers Wavequation Excel Discussion (Misc queries) 1 June 3rd 10 08:44 PM
Multiple Qualifiers HeatherMichelle Excel Discussion (Misc queries) 1 January 5th 10 03:54 AM
How do I set up an IF formula with multiple qualifiers? chubbs Excel Discussion (Misc queries) 4 September 10th 08 10:13 PM
Table lookup using multiple qualifiers TechMGR Excel Discussion (Misc queries) 1 January 11th 06 06:36 PM
XL2K Qualifiers Mike Mertes Excel Programming 1 November 18th 04 06:51 PM


All times are GMT +1. The time now is 10:30 PM.

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

About Us

"It's about Microsoft Excel"