Macro for message box if cell is blank

RAJESH1960

Active Member
Joined
Mar 26, 2020
Messages
494
Office Version
  1. 2019
Platform
  1. 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
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,416
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

Active Member
Joined
Mar 26, 2020
Messages
494
Office Version
  1. 2019
Platform
  1. 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,133,426
Messages
5,658,727
Members
418,466
Latest member
lisamck

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top