VBA - If a cell has a condition...

Lidsavr

Active Member
Joined
Jan 10, 2008
Messages
330
I am using Excel 2007 (and writing code that 2003 users must be able to run)

I need help with VBA code. I have tried searching the forum and several books, but cannot determine which command to use. Here is the situation.

If an ActiveCell contains a comma, then I want the code to run a text-to-columns command (which I have already written). Otherwise the ActiveCell drops one row and continues.

Here is what I have so far (the text in red is where I am stuck. Everything else works):

Code:
    [COLOR="Red"]If ActiveCell.FormatConditions(",") Then[/COLOR]        
        Selection.TextToColumns Destination:=Range("S2") _
            , DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False _
            , Tab:=False, Semicolon:=False, Comma:=True _
            , Space:=False, Other:=False, FieldInfo _
            :=Array(Array(1, 1), Array(2, 1), Array(3, 1)) _
            ,  TrailingMinusNumbers:=True
        Call Manage_Data
    Else
        ActiveCell.Offset(RowOffset:=1, ColumnOffset:=0).Select
    End If

NOTE: If the text-to-columns code above does not appear to work, it is because I reformatted it to fit in the code window above. In my program, it works well.

Thanks in advance for any help on the "If" line of code!

Charles
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try
Code:
If InStr(ActiveCell.Value2, ",") > 0 Then
Instr function checks for the specific character and if found, returns its position (which will then be greater than 0).
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,223
Members
452,896
Latest member
IGT

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