Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I found Chip Pearsons "Export to a Text File" instructions which work beautifully for the most part. I am having a little trouble getting the Export to start with the Row that I specify though. I have a header Record so I want my export to start with the 2nd Row. In the code below I have changed the start row to be 2 but the text file still has my header row listed. How can I force this code to start with the second row? Thanks Jody 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 If SelectionOnly = True Then With Selection StartRow = .Cells(2).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(2).Column End With Else With ActiveSheet.UsedRange StartRow = .Cells(2).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(2).Column End With End If Open FName For Output Access Write As #FNum For RowNdx = StartRow To EndRow WholeLine = "" For ColNdx = StartCol To EndCol If Cells(RowNdx, ColNdx).Value = "" Then CellValue = "" Else CellValue = Cells(RowNdx, ColNdx).Text End If WholeLine = WholeLine & CellValue & Sep Next ColNdx WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep)) Print #FNum, WholeLine Next RowNdx EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The simplest solution would be to set the StartRow to equal 2 as
follows......... If SelectionOnly = True Then With Selection StartRow = 2 StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(2).Column End With Else With ActiveSheet.UsedRange StartRow = 2 StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(2).Column End With End If -- Cheers Nigel "ssjody" wrote in message oups.com... Hi, I found Chip Pearsons "Export to a Text File" instructions which work beautifully for the most part. I am having a little trouble getting the Export to start with the Row that I specify though. I have a header Record so I want my export to start with the 2nd Row. In the code below I have changed the start row to be 2 but the text file still has my header row listed. How can I force this code to start with the second row? Thanks Jody 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 If SelectionOnly = True Then With Selection StartRow = .Cells(2).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(2).Column End With Else With ActiveSheet.UsedRange StartRow = .Cells(2).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(2).Column End With End If Open FName For Output Access Write As #FNum For RowNdx = StartRow To EndRow WholeLine = "" For ColNdx = StartCol To EndCol If Cells(RowNdx, ColNdx).Value = "" Then CellValue = "" Else CellValue = Cells(RowNdx, ColNdx).Text End If WholeLine = WholeLine & CellValue & Sep Next ColNdx WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep)) Print #FNum, WholeLine Next RowNdx EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Nigel, That worked. This VBA Rookie thanks you! Happy New Year!
|
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You have the routine screwed up now. Better to do it properly:
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 If SelectionOnly = True Then With Selection StartRow = .Cells(2,1).row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).row EndCol = .Cells(.Cells.Count).Column End With Else With ActiveSheet.UsedRange StartRow = .Cells(2,1).row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).row EndCol = .Cells(.Cells.Count).Column End With End If Open FName For Output Access Write As #FNum For RowNdx = StartRow To EndRow WholeLine = "" For ColNdx = StartCol To EndCol If Cells(RowNdx, ColNdx).Value = "" Then CellValue = Chr(34) & Chr(34) Else CellValue = Cells(RowNdx,ColNdx).Text End If WholeLine = WholeLine & CellValue & Sep Next ColNdx WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep)) Print #FNum, WholeLine Next RowNdx EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum End Sub -- Regards, Tom Ogilvy "ssjody" wrote in message oups.com... Nigel, That worked. This VBA Rookie thanks you! Happy New Year! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Force scale to start at zero | Charts and Charting in Excel | |||
Force excel to start new instance when I double-click a workbook | Excel Discussion (Misc queries) | |||
export re-order input fields to export file [csv] | Excel Worksheet Functions | |||
OT :Start your own online business today !start making dollars | Excel Discussion (Misc queries) | |||
Start spreadsheet with WinXP start | Excel Worksheet Functions |