The original code has some fixed assumptions about the data
1) The file names will always be in column "E"
2) The data to be written will always be in column "J" ( i.e. col 10)
3) The file name is on the same row as the data to be written.
If you are planning on keeping those basic assuptions then this should work.
Sub SaveSelectedRows()
Dim i As Long, LastDataRow As Long, StartRowNum As Long, EndRowNum As Long
Dim MyFile As String
Dim fnum, s
Dim UserRange As Range
'On Error GoTo Canceled
Set UserRange = Application.InputBox(Prompt:="Please Select Range", Title:="Range Select", Type:=8)
With UserRange
StartRowNum = .Cells(1, 1).Row
EndRowNum = .Cells(.Rows.Count).Row
End With
LastDataRow = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
If EndRowNum < LastDataRow Then
LastDataRow = EndRowNum
End If
For i = StartRowNum To LastDataRow
'-- Text Files Names : Column E
MyFile = "C:\Users\DJ-PC\Desktop\Text\" & ActiveSheet.Range("E" & i).Value & ".txt"
'-- Save Text in Column 10 (Column J) Cells
s = NewLn(Cells(i, 10).Text) & vbNewLine
fnum = FreeFile
Open MyFile For Output As fnum
Print #fnum, s
Close fnum
Next i
End Sub
If you want to change those restrictions, for example, specifying another column for filenames, then you'll need to explain more about how you want to change things.