Saturday, 8 December 2012

How To Import Data from a Text File using Excel VBA Macro

Excel VBA Macro To Import Data from a Text File and Keep in One Cell 
Sub ImpTxtFile()
 Dim A As Integer
 Dim B As Integer

    With ActiveSheet.QueryTables.ADD(Connection:= _
    "TEXT;C:\Documents and Settings\Administrator\Desktop\code1.txt" _
    , Destination:=Cells(1, 1))
    .Refresh BackgroundQuery:=True
    End With

For A = 1 To 100
Cells(1, 1) = Cells(1, 1) & Cells(A, 1)
Next A

For B = 2 To 100
Cells(B, 1).Clear
Next B

End Sub

Macro to Join all the imported text from all rows to First Row :
Sub JoinRows()
Dim A As Integer
Dim B As Integer

For A = 1 To 100
Cells(1, 1) = Cells(1, 1) & Cells(A, 1)
Next A

For B = 2 To A
 Cells(B, 1).Clear
Next B
'Pull out the search item from the Cell having the imported data.
Cells(4, 2) = Mid(Cells(1, 1), InStr(Cells(1, 1), "True") - 10, 30)
End Sub



--------------------------------------------------------------------------------------------------------
Thanks, TAMATAM ; Business Intelligence & Analytics Professional
--------------------------------------------------------------------------------------------------------

1 comment:

  1. I am not sure where you are getting your information, but great topic.
    I needss tto spend some tjme learning much more or understanding more.
    Thanks for wonderful information I was looking for thijs information for my mission.

    ReplyDelete

Hi User, Thank You for visiting My Blog. Please post your open Feedback only related to this Blog Posts. Please note that I cannot respond to the Anonymous Comments.

Subscribe to Blog Posts by Email

ExcelKingdom-Popular Posts