Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-13-2014, 08:43 AM
gebobs gebobs is offline Import data from CSV to table Windows 7 64bit Import data from CSV to table Office 2010 64bit
Expert
Import data from CSV to table
 
Join Date: Mar 2014
Location: Atlanta
Posts: 837
gebobs has a spectacular aura aboutgebobs has a spectacular aura about
Default Import data from CSV to table

Attached is a sanitized version of something I am working. The next objective is to automate importing and appending the data from a CSV with a few parameters:

1. the existing data in the Log table should be deleted
2. the data from the CSV should be appended to the existing Log table
3. there should be no blank rows when finished

Below was something I grabbed from another sheet I have. That one however just imports the data to a blank sheet so there's no existing table to deal with.

#1 is addressed. #3 can be addressed by simply deleting all but one row of data though I'm unsure how to do this in VBA. When pasting to a table, Excel automatically makes it large enough to accommodate all the data.



#2 is really where my meager VBA fails. Running as is, the data is inserted to the left of the table. I suppose what could be one is to have the table deleted entirely, import the data, and then create the table again. But if anyone has any ideas how I can eliminate that need, I'd appreciate it.

Sub CSV_Import()

Dim ws As Worksheet, strFile$

Selection.AutoFilter
Range("Log").Select
Selection.ClearContents

Set ws = ActiveWorkbook.Sheets("Log") 'set to current worksheet name

strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please select text file...")

With ws.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=ws.Range("A1"))
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh
End With

End Sub
Attached Files
File Type: xlsm getdistinct macro.xlsm (17.2 KB, 13 views)
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
import .mht file data to powerpoint Rubini MJ PowerPoint 0 07-24-2013 10:24 PM
Import data from CSV to table Data query import Gandalf Excel 9 02-12-2013 03:03 AM
Import excel data in to SQL Server DavidBrown Excel 0 08-08-2011 04:49 AM
Import Pics and Excel Data into PP? jawillyams PowerPoint 0 03-13-2011 01:03 PM
Import data from CSV to table Outlook data import Cunner Outlook 2 08-20-2010 02:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft