PDA

View Full Version : Loop help



austenr
07-23-2015, 11:15 AM
I want to modify the following code to be able to just select worksheets in a named range called "Contacts". If the sheet isn't in the range I do not want to select it.


For Each sht In wkbk.Worksheets
newWorkbook = SaveWorksheet(sht, folder)
' in here you could read some parts of your worksheet to determine where to send it

PostMsg "My subject", "My body", "someone@somewhere.com", newWorkbook
' Kill newWorkbook
Next sht

mancubus
07-23-2015, 11:43 AM
One way is



If Application.Countif(Range("Contacts"), sht.Name) > 0 Then

austenr
07-23-2015, 11:46 AM
before the for loop i assume.

mancubus
07-23-2015, 11:58 AM
You want to test if the sheet name exists in the named range.
if it exists the statements in the loop will be executed.

So within the loop.

Like:


For Each...
If...
'Other code within the loop
End If
Next