VBA Code - Exclude Header/Footer row in Format

gofalc

New Member
Joined
Aug 11, 2014
Messages
3
Inherited Script that needs a modification. Unfamiliar with VBA code.
Script creates file a text successfully and formats columns with Pipe, however I need to Exclude First and Last row (header/footer) with "PIPE".


Sub pipey()
'Create a text file with each row cell delimited with "|"


Dim intUsedrows As Long
Dim intUsedcolumns As Long


Dim rCell As Range
Dim rRow As Range
Dim sOutput As String
Dim sFname As String, lFnum As Long
Dim rowCount As Long


'Excel setup
Set xlApp = CreateObject("excel.application")
xlApp.DefaultSaveFormat = xlOpenXMLWorkbook
'Set xlWkb = xlApp.Workbooks.Add
'lWorkBookname = xlApp.ActiveWorkbook.Name
xlApp.Visible = True


xlApp.Workbooks.OpenText (IHTempLoc & "BRGLABS.TXT")


Open "L:\IT\MCK Reports\HAC\Humana\BRGLABS0.TXT" For Output As #1


With xlApp.Worksheets(1).Range("a:bf")
intUsedrows = xlApp.ActiveSheet.UsedRange.Rows.Count
intUsedcolumns = xlApp.ActiveSheet.UsedRange.Columns.Count


For i = 1 To intUsedrows
For J = 1 To intUsedcolumns - 1
If J <> 1 Or J <> 17 Then colFormat = Trim(.Cells(i, J)) Else
If (J = 1 Or J = 17) Then colFormat = Trim(Mid((.Cells(i, J)), 2))




Print #1, colFormat; "|";


Next J
Print #1, Trim(.Cells(i, intUsedcolumns))
Next i
End With


Close #1
xlApp.DisplayAlerts = False
xlApp.Quit


End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try changing your values for i in the For i loop.
Code:
For i = 2 To intUsedrows - 1
That should then begin on row 2 and stop on next to last row.
 
Upvote 0
Try changing your values for i in the For i loop.
Code:
For i = 2 To intUsedrows - 1
That should then begin on row 2 and stop on next to last row.


If I modify "For i = 2 To intUsedrows - 1" , it completely deletes my header/footer row. In my case, I want to keep the those rows but not format it;

Example;
Header Row -
01|HELLO|20140701||||||||||||||||||||||||||||||||||||||||||||||||||||||

NEED -
01 HELLO 20140701
 
Upvote 0

Forum statistics

Threads
1,216,577
Messages
6,131,511
Members
449,653
Latest member
andz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top