HELP! Sh as Worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm a newbie and as having trouble grasping something. I'm running code to
delete all empty sheets in a workbook. The code I have found begins with
Dim sh as Worksheets
For Each sh in ThisWorkbook.Worksheets
If Application.WorksheetFunction.Counta(sh.cells) = 0 Then
application.DisplayAlerts = False
sh.Delete
Application.DisplayAlerts=True
End if
Next

My questions is:

What does the sh as Worksheet mean in plain English?
I assume the Displayalerts means don't show me the confirmation message to
delete sheets

Thanks!
 
Hi,

You are assigning a variable for referencing the sheets in the workbook.
You could just as easily say;

For each sht in ThisWorkbook.Worksheets. You can assign whatever you would
like. Think of it as a quick way to reference the sheets. Look up
variables in the help file.

Yes, the display alerts does what you think it does.

HTH,

Job
 
It means you are telling vba you are going to use a variable named Sh in the
code which is of type Worksheet
For the DisplayAlerts, you' re right.

Sebastien
 
Hi,

Thank you both for your responses.

I guess I don`'t understand why I can't refer to the worksheet objects
directly. In other words, why do I have to assign a variable?

I guess I need lots of work in this area to understand it clearly, but with
the valuable help from people like you, I will eventually get it!

Thanks!



Job said:
Hi,

You are assigning a variable for referencing the sheets in the workbook.
You could just as easily say;

For each sht in ThisWorkbook.Worksheets. You can assign whatever you would
like. Think of it as a quick way to reference the sheets. Look up
variables in the help file.

Yes, the display alerts does what you think it does.

HTH,

Job
 
Thanks! I think I got it!
Thanks to you both!

Job said:
Hi,

You are assigning a variable for referencing the sheets in the workbook.
You could just as easily say;

For each sht in ThisWorkbook.Worksheets. You can assign whatever you would
like. Think of it as a quick way to reference the sheets. Look up
variables in the help file.

Yes, the display alerts does what you think it does.

HTH,

Job
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top