quickie: exclude a column in my code

Imrhien

New Member
Joined
May 5, 2011
Messages
27
G'day guys!

Need column P excluded from the following script:

Code:
    ' 12. Trim all cells to 28 characters
    Dim ws As Worksheet, c As Range
    For Each ws In Worksheets
        For Each c In Intersect(ws.UsedRange, ws.Cells(1, 1).EntireRow)
            On Error Resume Next
            ws.Columns(c.Column).TextToColumns Destination:=c, DataType:=xlFixedWidth, _
            FieldInfo:=Array(Array(0, 2), Array(28, 9))
            On Error GoTo 0
        Next c
    Next ws

The purpose of the code is to trim all cells to 28 characters, but column P needs to be excluded for my purposes. I don't understand the code very well so I'm not sure what to do.

Cheers!
 

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.
G'day guys!

Need column P excluded from the following script:

Rich (BB code):
    ' 12. Trim all cells to 28 characters
    Dim ws As Worksheet, c As Range
    For Each ws In Worksheets
        For Each c In Intersect(ws.UsedRange, ws.Cells(1, 1).EntireRow)
            On Error Resume Next
            ws.Columns(c.Column).TextToColumns Destination:=c, DataType:=xlFixedWidth, _
            FieldInfo:=Array(Array(0, 2), Array(28, 9))
            On Error GoTo 0
        Next c
    Next ws
The purpose of the code is to trim all cells to 28 characters, but column P needs to be excluded for my purposes. I don't understand the code very well so I'm not sure what to do.

Cheers!
Add the lines in red:
Rich (BB code):
 For Each c In Intersect(ws.UsedRange, ws.Cells(1, 1).EntireRow)
            If c.column <> 16 Then
            On Error Resume Next
            ws.Columns(c.Column).TextToColumns Destination:=c, DataType:=xlFixedWidth, _
            FieldInfo:=Array(Array(0, 2), Array(28, 9))
            On Error GoTo 0
            End IF
        Next c
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

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