![]() |
Imported text file to begin from the first empty cell
Hi
I want to import a textfile to excel worksheet. Problem is, that I want the imported data to begin in the first empty cell in column A. How do I do this? So far the macro is: Sub data_import() With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\O pticon\Data\Data.txt" _ , Destination:=Range("A1")) .Name = "Data" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = False .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 850 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = True .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With End Sub Thanks, Elina |
Imported text file to begin from the first empty cell
Add this line to the top of your code:
' finds first empty cell in Col A, starting from top of sheet lngLastRow = ActiveSheet.Cells(1, "A").End(xlDown).Row + 1 Then change your destination line: Destination:=Range("A" & lngLastRow) -- Cheers, Ryan "p11p00" wrote: Hi I want to import a textfile to excel worksheet. Problem is, that I want the imported data to begin in the first empty cell in column A. How do I do this? So far the macro is: Sub data_import() With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\O pticon\Data\Data.txt" _ , Destination:=Range("A1")) .Name = "Data" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = False .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 850 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = True .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With End Sub Thanks, Elina |
Imported text file to begin from the first empty cell
Thank you RyanH, this works, if I have 2 first rows filled for some reason.
Anyway I can use this. Cheers, Elina "RyanH" kirjoitti: Add this line to the top of your code: ' finds first empty cell in Col A, starting from top of sheet lngLastRow = ActiveSheet.Cells(1, "A").End(xlDown).Row + 1 Then change your destination line: Destination:=Range("A" & lngLastRow) -- Cheers, Ryan "p11p00" wrote: Hi I want to import a textfile to excel worksheet. Problem is, that I want the imported data to begin in the first empty cell in column A. How do I do this? So far the macro is: Sub data_import() With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\O pticon\Data\Data.txt" _ , Destination:=Range("A1")) .Name = "Data" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = False .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 850 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = True .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With End Sub Thanks, Elina |
Imported text file to begin from the first empty cell
If the first two rows always have something in them use this.
lngLastRow = ActiveSheet.Cells(2, "A").End(xlDown).Row + 1 I hope this helps! If so, then click "YES" below. -- Cheers, Ryan "p11p00" wrote: Thank you RyanH, this works, if I have 2 first rows filled for some reason. Anyway I can use this. Cheers, Elina "RyanH" kirjoitti: Add this line to the top of your code: ' finds first empty cell in Col A, starting from top of sheet lngLastRow = ActiveSheet.Cells(1, "A").End(xlDown).Row + 1 Then change your destination line: Destination:=Range("A" & lngLastRow) -- Cheers, Ryan "p11p00" wrote: Hi I want to import a textfile to excel worksheet. Problem is, that I want the imported data to begin in the first empty cell in column A. How do I do this? So far the macro is: Sub data_import() With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\O pticon\Data\Data.txt" _ , Destination:=Range("A1")) .Name = "Data" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = False .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 850 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = True .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With End Sub Thanks, Elina |
All times are GMT +1. The time now is 07:25 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com