midomimo
04-26-2018, 04:34 PM
Dear Team ,
Iam using the below for exporting range to txt files andi repeate the below for more than one range it was working fine before i add the IF statement , i need the if to check if the Cell ( AT5) is 0 then get MSG box and end the vba and dont continue for the next one else if it include a value then do the rest of the statement .
iam getting error else without if ?
appreciate your support .
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
Iam using the below for exporting range to txt files andi repeate the below for more than one range it was working fine before i add the IF statement , i need the if to check if the Cell ( AT5) is 0 then get MSG box and end the vba and dont continue for the next one else if it include a value then do the rest of the statement .
iam getting error else without if ?
appreciate your support .
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