+ Reply to Thread
Results 1 to 2 of 2

Exporting non contigous ranges

Hybrid View

  1. #1
    ozibryan
    Guest

    Exporting non contigous ranges

    I need to be able to send different data to diffeent groups. I have tried to
    use ranges to do this. e.g.

    I define a range, as folows ; ("ColFocus")

    =Sheet1!$A$1:$A$17,Sheet1!$I$1:$I$17,Sheet1!$H$1:$H$17,Sheet1!$E$1:$E$17

    This example always returns by Col:

    ************************************* by Col ***************

    Public Sub ExportToTextFile(FName As String, _
    Sep As String, SelectionOnly As Boolean)

    Dim WholeLine As String
    Dim FNum As Integer
    Dim RowNdx As Long
    Dim ColNdx As Integer
    Dim StartRow As Long
    Dim EndRow As Long
    Dim StartCol As Integer
    Dim EndCol As Integer
    Dim CellValue As String

    Application.ScreenUpdating = False
    On Error GoTo EndMacro:

    FNum = FreeFile

    Open FName For Output Access Write As #FNum

    Set t = Range("ColFocus")
    MaxRow = t.Rows.Count
    MaxCols = t.Columns.Count

    For Each r In Range("ColFocus")
    CellValue = r.Value
    WholeLine = WholeLine & CellValue & Sep
    WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
    Print #FNum, WholeLine; Sep
    CellValue = " "
    CellValue = "row " & r.Row & " Col " & r.Column
    WholeLine = WholeLine & CellValue & Sep
    WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
    Print #FNum, WholeLine; Sep
    Next r

    EndMacro:
    On Error GoTo 0
    Application.ScreenUpdating = True
    Close #FNum

    End Sub

    ************************************ end by Col *************

    How can I make this return a result "byrows" - what I need is a CSV file of
    records -reflecting the selected columns.

    Anu help gratefully appreciated, I could 'hardcide' a series of values but
    if I could use excel to select the desired format it could save a lot of
    work.





  2. #2
    Tom Ogilvy
    Guest

    Re: Exporting non contigous ranges

    Public Sub ExportToTextFile(FName As String, _
    Sep As String, SelectionOnly As Boolean)

    Dim WholeLine As String
    Dim FNum As Integer
    Dim RowNdx As Long
    Dim ColNdx As Integer
    Dim StartRow As Long
    Dim EndRow As Long
    Dim StartCol As Integer
    Dim EndCol As Integer
    Dim CellValue As Range
    Dim r As Range, t As Range

    Application.ScreenUpdating = False
    On Error GoTo EndMacro:

    FNum = FreeFile

    Open FName For Output Access Write As #FNum
    Set t = Range("ColFocus")
    For Each r In Range("ColFocus").Areas(1).Rows
    Set r1 = Intersect(r.EntireRow, t.EntireColumn)
    WholeLine = ""
    For Each CellValue In r1
    WholeLine = WholeLine & CellValue & Sep
    Next CellValue
    WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
    Print #FNum, WholeLine
    Next r

    EndMacro:
    On Error GoTo 0
    Application.ScreenUpdating = True
    Close #FNum

    End Sub

    --
    Regards,
    Tom Ogilvy

    "ozibryan" <ozibryan @discussions.microsoft.com> wrote in message
    news:75191085-7122-4972-B4D7-292E55654103@microsoft.com...
    > I need to be able to send different data to diffeent groups. I have tried

    to
    > use ranges to do this. e.g.
    >
    > I define a range, as folows ; ("ColFocus")
    >
    > =Sheet1!$A$1:$A$17,Sheet1!$I$1:$I$17,Sheet1!$H$1:$H$17,Sheet1!$E$1:$E$17
    >
    > This example always returns by Col:
    >
    > ************************************* by Col ***************
    >
    > Public Sub ExportToTextFile(FName As String, _
    > Sep As String, SelectionOnly As Boolean)
    >
    > Dim WholeLine As String
    > Dim FNum As Integer
    > Dim RowNdx As Long
    > Dim ColNdx As Integer
    > Dim StartRow As Long
    > Dim EndRow As Long
    > Dim StartCol As Integer
    > Dim EndCol As Integer
    > Dim CellValue As String
    >
    > Application.ScreenUpdating = False
    > On Error GoTo EndMacro:
    >
    > FNum = FreeFile
    >
    > Open FName For Output Access Write As #FNum
    >
    > Set t = Range("ColFocus")
    > MaxRow = t.Rows.Count
    > MaxCols = t.Columns.Count
    >
    > For Each r In Range("ColFocus")
    > CellValue = r.Value
    > WholeLine = WholeLine & CellValue & Sep
    > WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
    > Print #FNum, WholeLine; Sep
    > CellValue = " "
    > CellValue = "row " & r.Row & " Col " & r.Column
    > WholeLine = WholeLine & CellValue & Sep
    > WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
    > Print #FNum, WholeLine; Sep
    > Next r
    >
    > EndMacro:
    > On Error GoTo 0
    > Application.ScreenUpdating = True
    > Close #FNum
    >
    > End Sub
    >
    > ************************************ end by Col *************
    >
    > How can I make this return a result "byrows" - what I need is a CSV file

    of
    > records -reflecting the selected columns.
    >
    > Anu help gratefully appreciated, I could 'hardcide' a series of values but
    > if I could use excel to select the desired format it could save a lot of
    > work.
    >
    >
    >
    >




+ 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