Results 1 to 3 of 3

Thread: Can not copy data with VBA code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Mar 2021
    Posts
    1
    Rep Power
    0

    Can not copy data with VBA code

    With the help of the below code I am not able to copy the text in text files in excel cell if the text in file starts with "="
    How can I modify the code?

    Code:
    Sub santa()
        Dim r As Range, txt As String, msg As String
        With Sheets("input")
            For Each r In .Range("a2", .Range("a" & Rows.Count).End(xlUp))
                If r <> "" Then
                    If Dir(r.Text) <> "" Then
                        txt = CreateObject("Scripting.FileSystemObject").OpenTextFile(r.Text).ReadAll
                        r(, 2) = txt
                        r(, 3) = Join(Filter(Split(txt, vbNewLine), "VBA-2", True, 1), vbLf)
                    Else
                        msg = msg & vbLf & r.Text
                    End If
                End If
            Next
        End With
        If Len(msg) Then MsgBox "File not fouond" & msg
    End Sub
    Last edited by DocAElstein; 03-31-2021 at 05:46 PM. Reason: Code tags : [CODE] ..Your code here ... [/CODE]

Similar Threads

  1. Replies: 1
    Last Post: 01-30-2019, 04:23 PM
  2. Replies: 1
    Last Post: 03-11-2014, 06:03 PM
  3. Replies: 1
    Last Post: 10-16-2013, 05:06 PM
  4. VBA Code to Open Workbook and copy data
    By Howardc in forum Excel Help
    Replies: 16
    Last Post: 08-15-2012, 06:58 PM
  5. VBA code to copy data from source workbook
    By Howardc in forum Excel Help
    Replies: 1
    Last Post: 07-30-2012, 09:28 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •