I would like to add the highlighted things to the output. please see pic above.
VBA Code:
Sub GetOutput()
Dim LastRowIndex As Integer
Dim RowIndex As Integer
Dim UsedRng As Range
Dim ws As Worksheet
Dim Ot As Worksheet
Dim str As String
Dim rowL As Integer
Dim rowLast As Integer
Set ws = ActiveWorkbook.Sheets("Input")
Set Ot = ActiveWorkbook.Sheets("Output")
rowL = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
If rowL > 2 Then
Ot.UsedRange.EntireRow.Delete
Ot.Cells(1, 1) = ""
Ot.Cells(1, 6) = ""
Ot.Cells(1, 3) = ""
Ot.Cells(1, 5) = ""
Ot.Cells(1, 2) = ""
Ot.Cells(1, 4) = ""
Ot.Cells(1, 7) = ""
For i = 3 To rowL
If ws.Cells(i, 2) = "CK:" Then
rowLast = Ot.Cells(Ot.Rows.Count, "A").End(xlUp).Row + 1
Ot.Cells(rowLast, 1) = 3245543
Ot.Cells(rowLast, 6) = Null
Ot.Cells(rowLast, 7) = Null
Ot.Cells(rowLast, 3) = ws.Cells(i, 3)
Ot.Cells(rowLast, 5) = ws.Cells(i, 4)
Ot.Cells(rowLast, 2) = CDate(ws.Cells(i, 1))
'Ot.Cells(rowLast, 6) = Format(CDbl(ws.Cells(i + 1, 6)), "$ #,##0.00")
Ot.Cells(rowLast, 4) = Format(CDbl(ws.Cells(i + 2, 6)), "$ #,##0.00")
End If
Next i
End If
'Ot.Activate
'Call DoTheExport
End Sub
Public Sub ExportToTextFile(FName As String, _
Sep As String, SelectionOnly As Boolean, _
AppendData 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
ActiveWorkbook.Worksheets("OutPut").Activate
If SelectionOnly = True Then
With Selection
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
Else
With ActiveSheet.UsedRange
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
End If
If AppendData = True Then
Open FName For Append Access Write As #FNum
Else
Open FName For Output Access Write As #FNum
End If
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)
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
ActiveWorkbook.Worksheets("Main").Activate
End Sub
Sub DoTheExport()
Dim str As String
str = ActiveWorkbook.Path & "\Check Register " + Format(Now(), "DDMMMYYYY") _
& ".txt"
ExportToTextFile FName:=str, Sep:=",", _
SelectionOnly:=False, AppendData:=False
ActiveWorkbook.FollowHyperlink str, NewWindow:=True
End Sub
Last edited by a moderator: