Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Chris,
Ensure that you have a backup of your workbook before running the following macro in case it does not do exactly what you expect. Note the comments in the code where you might have to edit the code to replace the master worksheet name, path of the csv file and csv file name. If the csv file and master file are in the same folder then there is no need to replace the csv file path. Some people would use the last row of the used range to find the last row of data on the master worksheet. Not terribly reliable under some circumstances so I have used 'find the last cell with data'. Copying the used range from the csv file is not a problem under the circumstances that I have used it. Sub AppendData() Dim wbMaster As Workbook Dim wsMaster As Worksheet Dim lngLastRow As Long Dim strPath As String Dim strTxtFile As String 'Can edit 'ThisWorkbook.Path' in next line to 'actual text file path between double quotes strPath = ThisWorkbook.Path & "\" 'Edit "Import Test.csv" to your csv file name strTxtFile = "Import Test.csv" Set wbMaster = ThisWorkbook 'Edit "Sheet1" in next line to your 'Master worksheet name Set wsMaster = wbMaster.Sheets("Sheet1") 'Find last row of existing data in master sheet With wsMaster lngLastRow = .Cells.Find(What:="*", _ After:=.Cells(.Rows.Count, .Columns.Count), _ LookIn:=xlFormulas, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Row + 1 End With 'Open csv file Workbooks.Open Filename:=strPath & strTxtFile 'Copy the data from csv file and append to 'bottom of existing data in Master worksheet 'Note: the + 1 leaves one blank row between 'existing data and new appended data. 'Delete + 1 for no blank rows. ActiveWorkbook.ActiveSheet.UsedRange.Copy _ wsMaster.Cells(lngLastRow + 1, "A") 'Close the csv file Windows(strTxtFile).Close End Sub -- Regards, OssieMac |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro to determine chart name | Excel Programming | |||
Macro to determine values | Excel Programming | |||
how can you let macro determine to where to copy | Excel Discussion (Misc queries) | |||
Use Combo Box value to determine macro used | Excel Worksheet Functions | |||
Varibles determine macro to run | Excel Programming |