1. I added CODE tags to your macro - you can use the [#] icom and paste the macro code beween them to set it off and to format it
2. This is a 'one line' If/Then format. If the MsgBox was on a seperate line, there's no error
If Range("AT5") = 0 Then MsgBox Range("AT5") & ".txt" & "Export NoT completed No Data Found"
counter = counter + 1
End
Else
3. Indented and with blank lines added to visually seperate blocks
Sub Button3_Click()
Dim AK As Range, AL As Range
Dim output15 As String
'here to input the range of the dataa you need to export
If Range("AT5") = 0 Then
MsgBox Range("AT5") & ".txt" & "Export NoT completed No Data Found"
counter = counter + 1
End
Else
For Each AL In Range("AU7:AU66").Rows
For Each AK In AL.Cells
'Report out first blank cell found in Column A
output15 = output15 & AK.Value
Next AK
output15 = output15 & vbNewLine
Next AL
' here to enter the full path and the name of file that will be saved by the name of the departement
Open "C:\SPG-MI-Migration\F&PScripts\Users" & Range("AT5") & ".txt" For Output As #1
Print #1, output15
Close
MsgBox Range("AT5") & ".txt" & "Export completed"
counter = counter + 1
End If
End Sub