Code to exit sub when no data to resize.

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys
Once again I need your help to correct the code. When I tested this code in a different data, I faced a problem. At first, when I tested when one or more ledgers were not available in the data base that is LIst of ledgers in data base and ledgers in Paste data, it worked correctly. When I pasted a new data in Paste data sheet, the master data sheet it showed blank since all ledgers were available and hence it will exit the sub. But the problem is it copies the headings from cell C1:F1 to C2:F2 which in turn will effect the import Master sheet.
In the below line of code, it is already mentioned that if B2 = "", exit sub.
Rich (BB code):
Call Pre_XML_Code                                                                           ' Perform preliminary actions
'
    If Sheets("MasterData").Range("B2") = vbNullString Then                                     ' If B2 in MasterData is blank then ...
        MsgBox "All Ledgers Available. Press Generate Purchase.XML"                             '   Display message to user
        Exit Sub
and this line is where it is copying the headings
Rich (BB code):
If LedgerCount > 1 Then .Range("C2:E" & .Cells(Rows.Count, 2).End(xlUp).Row).FillDown   ' Copy the C2:E2 formulas down to last row of B
    End With
1. Query stop code from copying headings.xlsm
To understand the problem, Please, check once by deleting the names January to December from List of ledgers sheet. Then, enter the names from January to December in the List of ledgers sheet again and please re-check.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
VBA Code:
        'If Range("B2").Value = "" Then Exit Sub ' this line I tried but still didn't work
Maybe you just missed a dot, it should be:
VBA Code:
        If .Range("B2").Value = "" Then Exit Sub ' this line I tried but still didn't work
 
Upvote 0
Solution
VBA Code:
        'If Range("B2").Value = "" Then Exit Sub ' this line I tried but still didn't work
Maybe you just missed a dot, it should be:
VBA Code:
        If .Range("B2").Value = "" Then Exit Sub ' this line I tried but still didn't work
Yes. You are right. It worked after I placed the dot. Thank you very much Akuini.
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0
Yes. I checked 10 times. It has been corrected. But, one more issue I didn't notice. Will post as new tomorrow.
 
Upvote 0
Oops... I mean tonight. The light is already out. Thanks to you for pulling my leg till now with the Application.speech. speak query. ?
 
Upvote 0
I actually tried till now, but failed. I kept thinking I may learn something, but as you know that I don't have the basic knowledge of coding and you kept me on my toes all night. Maybe I will catch up one day.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

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