importing data from csv files in their respective sheets.

  • So i have 2 csv files i want to import, 1 contains (User data) and the other (Book data). each of them have their own sheets where the data has to be stored (USERS) and (BOOKS) currently if i click on the user sheet and import the book data in it the data appears the same goes for User data when i go to the BOOKS sheet. that's what im trying to prevent from happening but i got no clue on how to do it :/ . How much do i need to modify this import code to fix the issues im having?

    Code
    Dim xFileName As Variant Dim Rg As Range Dim xAddress As String Dim myLastRow As Long Worksheets("Books").Select ActiveSheet.UsedRange myLastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row      sinput = Application.InputBox("enter number 1 or 2" & vbLf & vbLf & "1. add" & vbLf & "2. replace", "enter number", 1) If sinput = False Then     Exit Sub Else     Select Case sinput         Case 1        myLastRow = myLastRow + 1          xFileName = Application.GetOpenFilename("CSV File (*.csv), *.csv", , "Failu Imports", , False)         If xFileName = False Then Exit Sub         On Error Resume Next         'Set Rg = Application.InputBox("choose cell where the import begins", "file import", Application.ActiveCell.Address, , , , , 8)         'Set Rg = Cells(myLastRow, 1).Address         'On Error GoTo 0         'If Rg Is Nothing Then Exit Sub         'xAddress = Rg.Address         With ActiveSheet.QueryTables.Add("TEXT;" & xFileName, Range(Cells(myLastRow, 1), Cells(myLastRow, 1)))     'Range(xAddress)             .FieldNames = True             .RowNumbers = False             .FillAdjacentFormulas = False             .PreserveFormatting = True             .RefreshOnFileOpen = False             .RefreshStyle = xlInsertDeleteCells             .SavePassword = False             .SaveData = True             .RefreshPeriod = 0             .TextFilePromptOnRefresh = False             .TextFilePlatform = 936             .TextFileStartRow = 2             .TextFileParseType = xlDelimited             .TextFileTextQualifier = xlTextQualifierDoubleQuote             .TextFileConsecutiveDelimiter = False             .TextFileTabDelimiter = False             .TextFileSemicolonDelimiter = False             .TextFileCommaDelimiter = True             .TextFileSpaceDelimiter = False             .TextFileTrailingMinusNumbers = True             .Refresh BackgroundQuery:=False         End With         MsgBox "Data added!"          Case 2          Range(Cells(2, 1), Cells(myLastRow, 5)).Clear         xFileName = Application.GetOpenFilename("CSV File (*.csv), *.csv", , "file import", , False)         If xFileName = False Then Exit Sub         On Error Resume Next         With ActiveSheet.QueryTables.Add("TEXT;" & xFileName, Range("A2"))             .FieldNames = True             .RowNumbers = False             .FillAdjacentFormulas = False             .PreserveFormatting = True             .RefreshOnFileOpen = False             .RefreshStyle = xlInsertDeleteCells             .SavePassword = False             .SaveData = True             .RefreshPeriod = 0             .TextFilePromptOnRefresh = False             .TextFilePlatform = 936             .TextFileStartRow = 2             .TextFileParseType = xlDelimited             .TextFileTextQualifier = xlTextQualifierDoubleQuote             .TextFileConsecutiveDelimiter = False             .TextFileTabDelimiter = False             .TextFileSemicolonDelimiter = False             .TextFileCommaDelimiter = True             .TextFileSpaceDelimiter = False             .TextFileTrailingMinusNumbers = True             .Refresh BackgroundQuery:=False         End With            MsgBox "Data replaced!"         Case Else             dummy = MsgBox(" Wrong input", vbCritical)     End Select End If


    any help or guidance is welcome, thank you in advance!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!