Loop to check if multiple sheets exisit

  • Thread starter Thread starter Legacy 93538
  • Start date Start date
L

Legacy 93538

Guest
Hi

I have the macro below which should loop though shName and do a check to see if the sheet exisits within a workbook (PPOld) and if it does then copy the data into the a sheet in another workbook (PPNew)

Code:
shName = "DE"
shFound = False
    For Each sh In Worksheets
       If LCase(sh.Name) = LCase(shName) Then
         shFound = True
         PPOld.Sheets(shName).cells.Copy Destination:=PPNew.Sheets(shName).Range("A1")
       End If
    Next

However it only works for one sheet and i need to check for two sheets "DE" and "PL".

Does anyone know how to be able to loop through multiple sheets?

Thank you

Jessicaseymour
 

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.
Perhaps like this

Code:
Dim ShName As Variant
For Each ShName In Array("DE", "PL")
    shFound = False
    For Each sh In Worksheets
       If LCase(sh.Name) = LCase(ShName) Then
         shFound = True
         PPOld.Sheets(ShName).Cells.Copy Destination:=PPNew.Sheets(ShName).Range("A1")
       End If
    Next sh
Next ShName
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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