Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cycle through worksheets & call texttocolumns

Status
Not open for further replies.

shinkley

IS-IT--Management
Jul 10, 2003
5
US
I have an Excel spreadsheet that is generated from a flat file. The file has different sections with group totals. I have set up a macro to import the data and place it onto different sheets.

however, the data is comma seperated. I am trying to loop though each worksheet, and use the texttocolumns method. however, i am unable to loop through the sheets.

i will post code dealing with looping through the sheets, since the macro works correctly up to this point

Code:
For Each ws In ThisWorkbook.Worksheets
  With ws
    If ActiveSheet.Name <> &quot;Sheet6&quot; Then
     Selection.TextToColumns Destination:=Range(&quot;A1&quot;), 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), Array(4, 1), Array(5, 1), Array(6, 1)), _
        TrailingMinusNumbers:=True
    End If
  End With
  
Next ws

i have placed msgboxes at the start of the loop, and i only get 1 iteration of the loop.

any suggestions?
 
Hi,

The ActiveSheet NEVER CHANGES!

And it really should not under most circumstances.

Just reference the ws sheet object as such...
Code:
  With ws
    If .Name <> &quot;Sheet6&quot; Then
     .Cells(1, 1).CurrentRegion.TextToColumns Destination:=Range(&quot;A1&quot;), 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), Array(4, 1), Array(5, 1), Array(6, 1)), _
        TrailingMinusNumbers:=True
    End If
  End With
:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top