+ Reply to Thread
Results 1 to 18 of 18

writing a loop to parse multiple sheets.

Hybrid View

  1. #1
    Registered User
    Join Date
    11-01-2006
    Posts
    24

    writing a loop to parse multiple sheets.

    Hello,

    i'm looking for help writing a loop that will perform the same action on 11 worksheets but stop if it gets to a sheet with no data in cell A1. The data in A1 will be text. The code I wrote below below does what I want it to, but I have to run it on each individual sheet. Any help would be greatly appreciated.

    ~Donny

     
    Sub parse()
        Columns("A:A").Select
        Application.CutCopyMode = False
        Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
            FieldInfo:=Array(Array(0, 1), Array(2, 1), Array(15, 1), Array(17, 1), Array(24, 1), _
            Array(25, 1), Array(32, 1), Array(33, 1), Array(40, 1), Array(42, 1), Array(50, 1), Array( _
            52, 1), Array(59, 1), Array(60, 1), Array(68, 1), Array(69, 1), Array(77, 1), Array(79, 1)) _
            , TrailingMinusNumbers:=True
        Range("B12").Select
    End Sub

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Does this help

    Sub loopSheets()
    Dim wsSheet As Worksheet
    
        For Each wsSheet In Worksheets
          MsgBox wsSheet.Name ' add your code here
        Next wsSheet
    
    End Sub

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    11-01-2006
    Posts
    24
    Thanks for the help, but this doesn't work.

    Any other ideas?

    ~Donny

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646
    Donny

    Try this.
    Sub ParseWS()
    Dim ws As Worksheet
        
        For Each ws In Worksheets
            With ws
                If .Range("A1") <> "" Then
                    .Range("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
                    FieldInfo:=Array(Array(0, 1), Array(2, 1), Array(15, 1), Array(17, 1), Array(24, 1), _
                    Array(25, 1), Array(32, 1), Array(33, 1), Array(40, 1), Array(42, 1), Array(50, 1), Array( _
                    52, 1), Array(59, 1), Array(60, 1), Array(68, 1), Array(69, 1), Array(77, 1), Array(79, 1)) _
                    , TrailingMinusNumbers:=True
            End With
        Next ws
    End Sub

  5. #5
    Registered User
    Join Date
    11-01-2006
    Posts
    24
    I think this will work, but I think I need to tell it what range of worksheets to parse as I don't want it to parse every worksheet in the workbook. Sorry, I should have been more clear in my description.


    ~Donny

  6. #6
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Hi, Donny. Will you need to list each worksheet? Or how exactly do you determine on which sheets this procedure will run?

    Jason

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1