Text to Column with Case Statement across certain sheets with same cell

tmcrouse

Board Regular
Joined
Apr 10, 2012
Messages
121
I have 14 sheets in one workbook and I want to run a text to column macro across only certain sheets that are identical. Here is my code and I am getting an error of: application defined or object defined error. I have the code pasted in my This Workbook and not Module. I have already tried this under Module. Any suggestions. The column that is required text to column is column B and that is identical across the worksheets I am performing this macro on. The destination in each is also identical.

Code:
Sub TextToColumns()
'Text to columns across multiple worksheets
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ThisWorkbook.Worksheets
Select Case UCase(ws.Name)
Case "COM", "Sheet1", "Sheet11", "Sheet12", "Sheet13"
'do not process anything
Case Else
ws.Columns(B).TextToColumns destinatation:=ws.Range("b2"), DataType:=xlDelimited, _
        TextQualifier:=xlNone, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
        Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _
        ), Array(14, 1)), TrailingMinusNumbers:=True
   End Select
Next ws
Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
There are 3 things wrong here
Code:
ws.Columns([COLOR=#ff0000]B[/COLOR]).TextToColumns [COLOR=#ff0000]destinatation[/COLOR]:=ws.Range("[COLOR=#ff0000]b2[/COLOR]"), DataType:=xlDelimited, _
Columns should be ("B") or (2)
Destination is misspelt
b2 should be B1, as you are doing the entire column you cant place it starting on row 2
 
Upvote 0
Code:
Sub TextToColumns()
'Text to columns across multiple worksheets
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ThisWorkbook.Worksheets
Select Case UCase(ws.Name)
Case "COM", "Sheet1", "Sheet11", "Sheet12", "Sheet13"
'do nothing
Case Else
ws.Columns(2).TextToColumns Destination:=ws.Range("B1"), DataType:=xlDelimited, _
        TextQualifier:=xlNone, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
        Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _
        ), Array(14, 1)), TrailingMinusNumbers:=True
   End Select
Next ws
Application.ScreenUpdating = True
End Sub

You are a genius
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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