View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
BeSmart BeSmart is offline
external usenet poster
 
Posts: 102
Default Test named range exists & exclude worksheet if it doesn't

Thanks OssieMac

I changed the code and it ran, however it duplicated the data from an
expected 2 worksheets x 6 times?
i.e. it found the first matching worksheet ok and pasted the data
it found the second matching worksheet ok but pasted it's data 5 times...

FYI - Worksheets I currently have (in the order they appear in now):
9 worksheets visible
- GRP Wkly Collection (no defined range name & excluded in code)
- GRP Qtrly Collection (no defined range name & destination sh excluded in
code)
- Overview Template (no defined range name & excluded in code)
* - Test Plan (has the defined range name)
* - Test Plan (2) (has the defined range name)
- Plan Amendments (no defined range name)
- Sampling Opportunities (no defined range name)
- Test Report (no defined range name)
- MBA Report (no defined range name)

I also have 3 worksheets hidden which don't include the defined range name.

* 2 of the visible worksheets have the defined range named "GRPResults"

In addition, the macro seems to reacts differently depending on which
worksheet you start running the macro from (a worksheet with the defined
range name versus one without)...

Do you think that this macro will have problems once the users get hold of
it? (i.e. is volatile in some way).

If yes, then perhaps I should use another easier method e.g. having a "cheat
cell" on the worksheets that contains a word e.g. "GRPResults" which I
include as part follows:

For Each sh In ActiveWorkbook.Worksheets
If sh.Name < "Overview Template" And sh.Range("A1") = "GRPResults" And
sh.Name < DestSh.Name And sh.Name < "GRP Wkly Collection" And sh.Visible =
True Then

But then I run the risk of a user deleting the text from cell A1 on one of
the worksheets and that data not being included....

--
Any advice???
BeSmart


"OssieMac" wrote:

I think that you have the Exit For in the wrong place. When the code reaches
the Exit For, it will immediately jump to the line of code after Next.
Therefore the Copy/Paste part of the code will never be executed.

The Exit For should be prior to the End If of the condition that you are
testing to determine if you want the code to proceed. I am not sure but it
appears that it probably should be prior to the End If where I have put the
asterisk line.

If LastRowSource + LastRowDest DestSh.Rows.Count Then
MsgBox "There are not enough rows in the Destsh"

'******************** 'Exit For maybe here.

End If

Exit For 'Code will always jump to line after Next

testRng.Copy
With DestLoc
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With

End If
End If
Next


--
Regards,

OssieMac