Called procedure ignoring "With Sheets" command

B

Bishop

I have a workbook with two worksheets: Tally Sheet and Catalyst.
I have 2 procedures in this workbook: TallySheetRep and BanSum.
BanSum take a list of data and deletes all the duplicates.
TallySheetRep takes the same data (after BanSum runs), formats it, and
places in my Tally Sheet worksheet.
I call BanSum from TallySheetRep. Here's the problem. If I run
TallySheetRep while in the Catalyst worksheet everything runs fine. But if I
run TallySheetRep while I'm in the Tally Sheet worksheet the code starts
deleting all the duplicate lines in the Tally Sheet worksheet. Here's the
basic layout of my two procedures:

Sub TallySheetRep()
Call BanSum
With Sheets("Catalyst")
...sort, edit, etc.
copy data to sheet Tally Sheet
With Sheets("Tally Sheet")
...populate some formulas
End Sub

Sub BanSum()
With Sheets("Catalyst")
...sort, delete dups, etc.
End Sub

It's like BanSum totally disregards 'With Sheets("Catalyst")' and runs the
code right on the Tally Sheet worksheet instead. Even if I'm on the Tally
Sheet worksheet shouldn't the BanSum code 'go to' the Catalyst worksheet when
it's called? Why is this happening?
 
P

Per Jessen

As you don't post your entire code this is only a guess.

You may miss leading dots which shall set the reference to Catalyst sheet
using the With statement.

With Sheets("Catalyst")
.Range("A1").ClearContents 'Clear A1 on sheet "Catalyst"
Range("A1").ClearContents 'Clear A1 on active sheet

Hopes this helps.
 
B

Bishop

That was EXACTLY the problem. I had a few Cells(#,#) references in the
BanSum code and I didn't put a . in front of them. Thanks!!!
 

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

Top