Macro for message box if cell is blank

RAJESH1960

Board Regular
Joined
Mar 26, 2020
Messages
113
Office Version
2019
Platform
Windows
Hi, I have created a Macro to Generate XML. It will select the data from Sheet1 from cellA2. If cell A2 is blank then too message is displayed as XML generated

I want to add a code inbetween where if cell A2 is blank it should display a message box “Data Not Entered". and should not generate XML until data is entered



Sub SaveASPurchaseXML()

Dim rngData As Range

Dim strData As String

Dim strTempFile As String

Dim x As Long, y As Long

Dim usr As String

y = Sheets("Sheet2").Range("A2").CurrentRegion.Columns.Count

x = Sheets("Sheet1").Range("A2:A" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row).Rows.Count

Range("A2").Resize(x, y).Copy
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,193
Maybe:
VBA Code:
Sub SaveASPurchaseXML()
    Dim rngData As Range, strTempFile As String, x As Long, y As Long, usr As String
    If Sheets("Sheet1").Range("A2") = "" Then
        MsgBox "Data Not Entered"
        Exit Sub
    Else
        y = Sheets("Sheet2").Range("A2").CurrentRegion.Columns.Count
        x = Sheets("Sheet1").Range("A2:A" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row).Rows.Count
        Range("A2").Resize(x, y).Copy
    End If
End Sub
 

RAJESH1960

Board Regular
Joined
Mar 26, 2020
Messages
113
Office Version
2019
Platform
Windows
Maybe:
VBA Code:
Sub SaveASPurchaseXML()
    Dim rngData As Range, strTempFile As String, x As Long, y As Long, usr As String
    If Sheets("Sheet1").Range("A2") = "" Then
        MsgBox "Data Not Entered"
        Exit Sub
    Else
        y = Sheets("Sheet2").Range("A2").CurrentRegion.Columns.Count
        x = Sheets("Sheet1").Range("A2:A" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row).Rows.Count
        Range("A2").Resize(x, y).Copy
    End If
End Sub
😂
Thanks Mumps..It Worked.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,561
Messages
5,487,571
Members
407,605
Latest member
PACULA

This Week's Hot Topics

Top