Msg Box displaying sheet names to be appended

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello experts,
This is an image of a sample workbook with 5 different sheet names. There are a minimum 4 sheets in any workbook which may have up to 8 or more sheets in different scenarios. With the help of my code, I append all the sheets in the workbook except Z and X . I need your expertise to help me with a code to add it in the beginning of the code. When I run the code, before the code appends the sheets, I want the message box to display, " Are you sure you want to append sheets A, B and C." with a Yes No option in the message box. The code should read all the names of the sheets in the workbook except Z and X. If there are only two sheets other than Z and X then the msg. box should display a message box stating those sheets names and similarly if there are 4 or more sheets other than Z and X then it should display message box with all the four names of the sheets.
In short, when I run the code, the code should display the message, the code is going to append sheets except Z and X.
Thank you in advance.
 

Attachments

  • Untitled.png
    Untitled.png
    2.9 KB · Views: 11

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
How about this...

VBA Code:
Sub GetShtNames()
    Dim i As Long, nams As String
    For i = 1 To Worksheets.Count
        If Worksheets(i).Name <> "Z" And Worksheets(i).Name <> "A" Then
            nams = nams & ", " & Worksheets(i).Name
        End If
    Next
    MsgBox "Are you sure you want the code to append these sheets:" & Mid(nams, 2), vbYesNo
End Sub
 
Upvote 0
Solution
You're welcome, I was happy to help. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

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