Hi.
I currently modifying a module that will export the "columns" if the column includes text "Include" from Row 1.
This works fine except I want it to start exporting at Row 3 rather than Row 2. No matter what I do it still starts exporting from Row 2. What am I doing wrong?
Current Code"
Public bForm As Boolean
Private Sub Export_Click()
ExportToTXT
End Sub
Sub ExportToTXT()
'
' Exports the identified column to a Comma Delimited Text File
' Last Revised 2/2/2011
'
Dim iTab As Integer
Dim iNumCols As Integer
Dim iNumRows As Integer
Dim iCol As Integer
Dim iRow As Integer
Dim sDestFolder As String
Dim sNewFileName As String
Dim sTextLine As String
Dim bContinue As Boolean
'Ask user to select the tabs
frmSelectTabs.Show
If bForm = False Then
MsgBox "Selection canceled by user.", vbInformation
Exit Sub
End If
sDestFolder = ""
sDestFolder = SelectFolder()
If sDestFolder = "" Then
MsgBox "Selection canceled by user.", vbInformation
Exit Sub
Else
For iTab = 0 To frmSelectTabs.lbTabs.ListCount - 1
If frmSelectTabs.lbTabs.Selected(iTab) = True Then
Worksheets.Item(frmSelectTabs.lbTabs.List(iTab)).Activate
ActiveSheet.UsedRange 'This resets the used range
ActiveSheet.UsedRange.Select
iNumCols = Selection.Columns.Count
iNumRows = Selection.Rows.Count
'Check to make sure there that the current tab actually has columns to be include in the export
bContinue = False
For iCol = 1 To iNumCols
If InStr(1, UCase(Cells(1, iCol).Value), "INCLUDE") <> 0 Or _
InStr(1, UCase(Cells(1, iCol).Value), "EXPORT") <> 0 Then
bContinue = True
End If
Next iCol
If bContinue = True Then
sNewFileName = sDestFolder & ActiveSheet.Name
Open sNewFileName For Output As #1
For iRow = 1 To iNumRows 'Sets the Default starting location for exporting 1
sTextLine = ""
For iCol = 1 To iNumCols
If InStr(1, UCase(Cells(1, iCol).Value), "INCLUDE") <> 0 Or _
InStr(1, UCase(Cells(1, iCol).Value), "EXPORT") <> 0 Then
sTextLine = sTextLine & Cells(iRow, iCol).Value & ","
End If
Next iCol
sTextLine = Left(sTextLine, Len(sTextLine) - 1)
Print #1, sTextLine
Next iRow
Close #1
Range("A1").Select
MsgBox ("The tab titled '" & ActiveSheet.Name & "' did not contain any columns to be included" & vbCr & _
"in the file export and was skipped.")
End If
End If
Next iTab
End If
'Changes Active Workheet
Worksheets(5).Activate
Range("A1").Select
End Sub
Sample Excel File:
See attached Image.
Sample Output in text format:
Enter Type Names:,parameter name##parameter type##unit##
,Enter Name##OTHER##
type name1,value1
type name2,value2
This line should not be here:
Enter Type Names:,parameter name##parameter type##unit##
Bookmarks