Create txt or cvs file base on cells with filter

snowdance0

New Member
Joined
Apr 19, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi, Is there a way to create text file base form hundred of ID, and for each text file's content would be IP address as attached pict.
 

Attachments

  • 1.png
    1.png
    11.6 KB · Views: 8
  • 2.png
    2.png
    3.5 KB · Views: 8
  • 3.png
    3.png
    15.6 KB · Views: 8

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I actually want text file with tab delimiter but I could also work with csv.
 
Upvote 0
Actually It would be perfect if the text file and the content inside would go like this
1650406040955.png
 
Upvote 0
Ok, but it requires more explanation.
Does every ID need one file or do you need 1 textfile for the unique ID's?
 
Upvote 0
Specify your path and it should work.
I assumed that your data is in columns A and B

VBA Code:
Sub jec()
 Dim ar, i As Long, sq As String, xPath As String
 
 ar = Range("A2:B" & Range("A" & Rows.Count).End(xlUp).Row)
 xPath = "C:\Users\xx\xx\xxx\"
 
 With CreateObject("scripting.filesystemobject")
   For i = 1 To UBound(ar)
      sq = xPath & ar(i, 1) & ".txt"
      If .FileExists(sq) Then
        .createtextfile(sq).write .opentextfile(sq).readall & vbCrLf & ar(i, 2)
      Else
        .createtextfile(sq).write ar(i, 2)
      End If
    Next
 End With
End Sub
 
Last edited:
Upvote 0
Solution
Specify your path and it should work.
I assumed that your data is in columns A and B

VBA Code:
Sub jec()
 Dim ar, i As Long, sq As String, xPath As String
 
 ar = Range("A2:B" & Range("A" & Rows.Count).End(xlUp).Row)
 xPath = "C:\Users\xx\xx\xxx\"
 
 With CreateObject("scripting.filesystemobject")
   For i = 2 To UBound(ar)
      sq = xPath & ar(i, 1) & ".txt"
      If .FileExists(sq) Then
        .createtextfile(sq).write .opentextfile(sq).readall & vbCrLf & ar(i, 2)
      Else
        .createtextfile(sq).write ar(i, 2)
      End If
    Next
 End With
End Sub
Thank you so much. This work perfectly.
 
Upvote 0
I did a small change. I still had i=2 to…
It should be i=1
 
Upvote 0

Forum statistics

Threads
1,216,816
Messages
6,132,861
Members
449,761
Latest member
AUSSW

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top