Consulting

Results 1 to 2 of 2

Thread: Stop Importing file after 'End Records'

  1. #1
    VBAX Regular
    Joined
    Feb 2011
    Posts
    34
    Location

    Stop Importing file after 'End Records'

    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.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Hi
    consider uploading your txt and xlsm files.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •