Macro for message box if cell is blank

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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
 
Upvote 0
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.
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,214,377
Messages
6,119,183
Members
448,872
Latest member
lcaw

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
Back
Top