Optional MsgBox to appear

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello Experts

I am trying to fit 2 MsgBox in one code, but it should display one only depending on the conditions in the code.
Right now the code runs and displays MsgBox ("File saved on Desktop as Master.XML.") even if there is no data.
I want to add just one line of code in the beginning.
If, in sheet MasterData cell B2 is Blank and when I press the button macro, the MsgBox should display “All Ledgers Available.” and stop from running the rest of the code.

Else, the code should continue to run and on completion, the MsgBox should display “File saved on Desktop as Master.XML.”.
Rich (BB code):
Option Explicit
Sub GenerateMasterXML()
'solved by JohnnyL

'
    Dim LastColumnNumberInRow               As Long
    Dim x                                   As Long
    Dim xmlFile                             As Object
    Dim LastColumnLetterSheetImportMasters  As String
    Dim strData                             As String
    Dim strTempFile                         As String
'
    x = Sheets("MasterData").Range("B2:B" & Sheets("MasterData").Range("B" & Rows.Count).End(xlUp).Row).Rows.Count  ' Get count of rows to write to file
'
    LastColumnNumberInRow = Sheets("ImportMasters").Cells(2, Sheets("ImportMasters").Columns.Count).End(xlToLeft).Column  ' Get last column number in row
'
    LastColumnLetterSheetImportMasters = Split(Cells(1, (Sheets("ImportMasters").Cells.Find("*", , xlFormulas, _
            , xlByColumns, xlPrevious).Column)).Address, "$")(1)                                            ' Get last column letter used in Sheets("ImportMasters")
'
    Sheets("ImportMasters").Range("A2:" & LastColumnLetterSheetImportMasters & x + 1).FillDown                  ' Create range needed to copy
'
    Sheets("ImportMasters").Range("A2").Resize(x, LastColumnNumberInRow).Copy
'
    strData = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("Text")                               ' Save contents into strData
'
    strTempFile = "C:\Users\" & Environ("username") & "\Desktop\Master.xml"
    CreateObject("Scripting.FileSystemObject").CreateTextFile(strTempFile, True).Write strData                  ' Write the data to file
'
    Application.CutCopyMode = False

    
    Application.Calculation = xlAutomatic
    Application.ScreenUpdating = True
    MsgBox ("File saved on Desktop as Master.XML.")
End Sub
 
They are exactly the same thing, except that for some reason, the forum swapped my leading double quote (") with another type of quote character, and I can tell you from experience that those characters are not usually acceptable in vba code. I have to think that if your code contains it, that's the reason why.

EDIT - I see the problem is already identified.
Yeah, the pay is the same but so is the effort. Yesterday I gave a more robust solution that taught the use of additional and potentially beneficial techniques and got the same result, so it can be a bit tiresome after a time. Mostly, I was looking for a reason in this case which could have been provided but wasn't.
No problem.
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
They are exactly the same thing, except that for some reason, the forum swapped my leading double quote (") with another type of quote character, and I can tell you from experience that those characters are not usually acceptable in vba code. I have to think that if your code contains it, that's the reason why.

EDIT - I see the problem is already identified.
Yeah, the pay is the same but so is the effort. Yesterday I gave a more robust solution that taught the use of additional and potentially beneficial techniques and got the same result, so it can be a bit tiresome after a time. Mostly, I was looking for a reason in this case which could have been provided but wasn't.
No problem.
Micron, I really appreciate your effort man. You tried and helped me that is great. I believe it is always the thought that counts.
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,825
Members
449,190
Latest member
rscraig11

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