Hello there,
I am working on a personal project.
Goal: I want to click the button that is linked to this Macro, and have the Macro check to see if a certain cell (F2) on a certain sheet (Generator) is equal to Error. If that cell's value is Error or "ERROR", then I want the Critical Error to show and stop the export of the file to .txt.
If cell value is blank or 0, then I want the macro to proceed with the export.
I seem unable to change the code I have to do what I want. Therefore current code does that step. This code currently functions 100%, it just doesn't check for the "Error".
Thanks in advance
I am using Windows 7 with Excel 2010
I am working on a personal project.
Goal: I want to click the button that is linked to this Macro, and have the Macro check to see if a certain cell (F2) on a certain sheet (Generator) is equal to Error. If that cell's value is Error or "ERROR", then I want the Critical Error to show and stop the export of the file to .txt.
If cell value is blank or 0, then I want the macro to proceed with the export.
I seem unable to change the code I have to do what I want. Therefore current code does that step. This code currently functions 100%, it just doesn't check for the "Error".
Thanks in advance
I am using Windows 7 with Excel 2010
Code:
Sub export2txt()
Dim lastColumn As Integer
Dim lastRow As Integer
Dim strString As String
Dim i As Integer, j As Integer
Dim UD As String
Dim warning
UD = CreateObject("WScript.Shell").specialfolders("Desktop")
UD = UD & "\Export.txt"
Worksheets("EXPORT").Activate
lastColumn = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.Count
lastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
warning = MsgBox("One or more of the selected Systems are incompatible with the size of the ship you have chosen", vbOKOnly + vbCritical, "Warning")
If warning = vbOK Then Exit Sub
Open UD For Output As #1
For i = 1 To lastRow
Cells(i, 1).Select
strString = ""
For j = 1 To lastColumn
If j <> lastColumn Then
strString = strString & Cells(i, j).Value & "," ' Use semicolon instead of pipe.
Else
strString = strString & Cells(i, j).Value
End If
Next j
Print #1, strString
Next i
Close #1
Worksheets("Generator").Activate
End Sub