LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Trying to determine if macro is possible

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to determine chart name Fan924 Excel Programming 5 September 30th 09 02:44 PM
Macro to determine values [email protected] Excel Programming 1 June 9th 09 05:53 AM
how can you let macro determine to where to copy mohavv Excel Discussion (Misc queries) 1 May 29th 08 08:15 AM
Use Combo Box value to determine macro used Richhall[_2_] Excel Worksheet Functions 1 January 4th 08 01:28 PM
Varibles determine macro to run Dennis Lavallee Excel Programming 4 May 19th 06 03:26 PM


All times are GMT +1. The time now is 09:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"