Folks,

Good Saturday.

I wanted to save a selection to text files.

So I use the input box select my rows and it should save them to my text files on my desktop.

So i did some stuff and well - its not happening

Please can a pro help me see why my range doesnt work

 

    Sub SaveSelectedRows()
     

    Dim i As Long
    Dim LastDataRow As Long
    Dim MyFile As String
    Dim fnum
    
    
    Dim UserRange As Range
    'On Error GoTo Canceled
    Set UserRange = Application.InputBox(Prompt:="Please Select Range", Title:="Range Select", Type:=8)
    
     
    
    'LastDataRow = ActiveSheet.Range(UserRange)
    
     'LastDataRow = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
     
    For i = 4 To LastDataRow
     
     
    '--  Text Files Names : Column E
    
    'MyFile = "C:\Users\DJ-PC\Desktop\Text\" & ActiveSheet.Range("E" & i).Value & ".txt"
     
    MyFile = "C:\Users\DJ-PC\Desktop\Text\" & ActiveSheet.Range(UserRange).Value & ".txt"
     
    
    '-- Save Text in Column 10 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
    
    
    
    Private Function NewLn(s As String) As String
    NewLn = Replace(s, vbLf, vbNewLine)
    
    End Function
it works normally - but i wanted to use a input box becuase i have to keep changing the code when i need different rows only

Thank you for the help