1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Write Count of Cells w/ Data to Text File

Discussion in 'Business Applications' started by Carlos_Mendoza, Jan 31, 2012.

Thread Status:
Not open for further replies.
  1. Carlos_Mendoza

    Carlos_Mendoza Thread Starter

    Joined:
    Nov 12, 2011
    Messages:
    124
    I have about 10 workbooks. Each workbook has two worksheets. I need a way to for each of the workbooks write to a text file, the worksheet name and a count of cells with data - the top 2 rows for header information. So for example, let's say that WB1 has two worksheets named WS1 and WS2 I would need the text file to read something like this WB1!WS1 = 10, WB1!WS2 = 12, then in the same text file have the next workbook (following the same schema) WB2!WS1 = 13, WB2!WS2 = 20

    So the text file would just have that data stacked like this
    WB1!WS1 = 10
    WB1!WS2 = 12
    WB2!WS1 = 13
    WB2!WS2 = 20

    and carry on this same trend for each workbook.
     
  2. jo15765

    jo15765

    Joined:
    Oct 11, 2011
    Messages:
    307
    Someone wrote this function for me and it looks like it may be something similar to what you are needing.

    Code:
    Sub WriteToTxtFile()
    Dim WB As Workbook, WS As Worksheet, i As Integer, r As Range
    Dim fn As String, s As String
    Dim fPath As String
    fPath = "Location of the Workbooks you are wanting to count data in"
    For Each WB In Workbooks
        If LCase(GetBaseName(WB.FullName)) = "personal" Then GoTo NextWB
            For Each WS In WB.Worksheets
                fn = WS.Name & ".txt"
                s = s & GetBaseName(WB.FullName) & "!" & WS.Name & " = " & (WS.Range("A" & Rows.Count).End(xlUp).Row) & vbCrLf
            Next WS
            If Dir(fPath & "\" & fn) Then Kill fPath & "\" & fn
            AppendToTXTFile fPath & "\" & fn, s
    NextWB:
    Next WB
    End Sub
    
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Solved Write Count
  1. pdevoid
    Replies:
    0
    Views:
    112
  2. phyljack1
    Replies:
    6
    Views:
    221
  3. megarich
    Replies:
    1
    Views:
    253
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1038933

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice