If statments, PLEASE HELP

imported_unknown

Active Member
Joined
Jan 13, 2002
Messages
424
Is it possible for me to set an IF statement to do nothing if a criteria is not met. For example:

my IF statement in the D column is

IF(A:A = "dog", "bark")

I want to be able to do this without affecting the D column for records that do not currently have "dog" in the A column, right now, what happens is if the records don't have "dog" in the A column FALSE is entered in the D column.
 
On 2002-10-04 17:15, lenze wrote:
You will need to use code. Something like:

Sub Fixit()
Dim cel As Range
Dim myVar As Range
Set myVar = Selection
For Each cel In myVar
If cel.Value = "dog" Then cel.Offset(0, 1).Value = "bark"
Next

End Sub

Select the cells in column A and run the macro

here is my code:
Sub Battery()

Dim cel As Range
Dim myVar As Range
Set myVar = Selection
For Each cel In myVar
If cel.Value = "PPC6V2.5M" Then cel.Offset(0, 2).Value = "B01054"
Next

End Sub

I selected the entire A column and tried to execute the macro and then the error
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I don't know what is wrong. I put sample data in column A including your test data
PPC6V2.5M and copied your code to a module. I selected the column and ran the Macro. It worked fine. Where are you placing your code? It needs to be in a regular module.
It's Friday and I'm leaving, but maybe someone else can check it out and see if they get an error.
This message was edited by lenze on 2002-10-04 17:55
 
Upvote 0
Hi,

What happens if you select only 1 cell containing "PPC6V2.5M" and run the macro?
 
Upvote 0
Thank you for the help, it did work.
If I want to input info into two columns at once shouldn't this code work? Or do I need to declare another variable?

Dim cel As Range
Dim myVar As Range
Set myVar = Selection
For Each cel In myVar
If cel.Value = "PPC6V2.5M" Then cel.Offset(0, 2).Value = "B01054" And cel.Offset (0, 3).Value = "6V"
Next

End Sub
 
Upvote 0
Try it this way

Sub Fixit()

Dim cel As Range
Dim myVar As Range
Set myVar = Selection
For Each cel In myVar
If cel.Value = "PPC6V2.5M" Then
cel.Offset(0, 2).Value = "B01054"
cel.Offset(0, 3).Value = "6V"
End If
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top