PDA

View Full Version : Stop Importing file after 'End Records'



Foncesa
09-23-2021, 07:57 AM
Hi,
Open xyz.csv file.


Sub Load()Dim wb As Workbook
Dim pickfile As Variant
pickfile = Application.GetOpenFilename(FileFilter:="CSV Files (*.csv), *.csv", _
Title:="Choose File:: FILE", MultiSelect:=False)
If pickfile = False Then Exit Sub
Set wb = Workbooks.Open(pickfile, True, False) ' open the source workbook with write permissions
End Sub

My xyz.csv file is 10 columns, i import the selected Columns data through a script.

Public Sub MData() Application.ScreenUpdating = False
Dim wb1 As Workbook, wb2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Dim lastrow As Long, NextRow As Long
Set wb1 = ThisWorkbook
Set wb2 = ActiveWorkbook
Set ws1 = wb1.Sheets("NEWDATA")
Set ws2 = wb2.Worksheets(1)
lastrow = ws2.Cells(Rows.Count, 1).End(xlUp).row
NextRow = ws1.Cells(Rows.Count, 1).End(xlUp).row + 1


For i = 2 To lastrow
ws1.Cells(NextRow, 1) = ws2.Cells(i, 5)
ws1.Cells(NextRow, 2) = ws2.Cells(i, 10)
ws1.Cells(NextRow, 3) = ws2.Cells(i, 4)

NextRow = NextRow + 1
Next i
wb2.Close SaveChanges = False
ws1.Activate
Set wb1 = Nothing
Set wb2 = Nothing
Set ws1 = Nothing
Set ws2 = Nothing
End Sub

Now, I want to stop importing the data after End Records found in Column D in xyz.csv file.

One more thing i want to do, add 'ND' Flag for all the records imported in column D.

Experts please find out a solution for this situation.
Thanks in advance.

mancubus
09-28-2021, 03:45 AM
Hi
consider uploading your txt and xlsm files.