Saturday, December 8, 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
--------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog