Hello
Your Help shall be appreciated.
I am trying to display all the Records of Text file which does not exists/Match in Worksheet and to paste them
I've implemented the following code but somehow not successful.
The following code displays the Non-Matched Value of Worksheet against the Textfile and The rest Non-Matched values are not displayed.
When following below syntax changed to
Set rng = Worksheets("Sheet1").Range("A2:A" & lstRow) then Nothing Displays.
Else
with following syntax
Set rng = Worksheets("Sheet1").Range("A1").currentRegion.columns(1)
It only displays the NonMatched value of A1 = "Date" which is in the header row and Does not display other non matched Dates
What is desired is to Display all the Dates, Ref Nos and Amount not Found in XLworksheet but which are in Text file
NOTE :Dates could be different or same, Ref No will always be different, Amounts could be Same or Different
Structure of text file
Structure of XL worksheet
Desired output in Msgbox
Following Records Not found in Sheet1
05-09-2022
Reference No I194
Amount 13,284.00
05-09-2022
Reference No I683
Amount 3,000.00
05-09-2022
Reference No I421
Amount 6,500.00
Thanks
NimishK
Your Help shall be appreciated.
I am trying to display all the Records of Text file which does not exists/Match in Worksheet and to paste them
I've implemented the following code but somehow not successful.
The following code displays the Non-Matched Value of Worksheet against the Textfile and The rest Non-Matched values are not displayed.
VBA Code:
Private Sub cmdNonMatchRecordsOfTextFile_Click()
Dim txtFileName As String, strDataTxtFile As String, nosline As String, lineCount As Integer
Dim txtMatched As String, txtNotMatched As String, msg As String
Dim rng As Range, c As variant, lstRow As Long
txtFileName = "C:\Matching\Records.txt"
Open txtFileName For Input As #1
While Not EOF(1)
Line Input #1, strDataTxtFile
nosline = nosline & strDataTxtFile & vbCrLf
Wend
Close #1
TextBox1.Text = TextBox1.Text & nosline
Worksheets("Sheet1").Activate
With Worksheets("Sheet1")
lstRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Set rng = Worksheets("Sheet1").Range("A1").currentRegion.columns(1)
''Or
''Set rng = Worksheets("Sheet1").Range("A1:A" & lstRow)
For Each c In rng.Rows
If InStr(nosline, c) > 0 Then
''''''txtMatched = txtMatched & c & ","
Else
txtNotMatched = txtNotMatched & c & ","
End If
Next
'''''txtMatched = Left(txtMatched, Len(txtMatched) - 1)
txtNotMatched = Left(txtNotMatched, Len(txtNotMatched) - 1)
''''msg = "Following Records Found in Sheet1 " & txtMatched
msg = "Following Records Not found in Sheet1" & txtNotMatched
MsgBox msg
End Sub
Set rng = Worksheets("Sheet1").Range("A2:A" & lstRow) then Nothing Displays.
Else
with following syntax
Set rng = Worksheets("Sheet1").Range("A1").currentRegion.columns(1)
It only displays the NonMatched value of A1 = "Date" which is in the header row and Does not display other non matched Dates
What is desired is to Display all the Dates, Ref Nos and Amount not Found in XLworksheet but which are in Text file
NOTE :Dates could be different or same, Ref No will always be different, Amounts could be Same or Different
Structure of text file
29-08-2022
Reference Number N485
Amount 38,104.00
30-08-2022
Reference Number I076
Amount 1,13,104.00
05-09-2022
Reference No I194
Amount 13,284.00
05-09-2022
Reference No I683
Amount 3,000.00
05-09-2022
Reference No I421
Amount 6,500.00
Structure of XL worksheet
Date | Reference No | Amount |
29-08-2022 | N485 | 38104.00 |
30-08-2022 | I076 | 113104.00 |
Desired output in Msgbox
Following Records Not found in Sheet1
05-09-2022
Reference No I194
Amount 13,284.00
05-09-2022
Reference No I683
Amount 3,000.00
05-09-2022
Reference No I421
Amount 6,500.00
Thanks
NimishK
Last edited: