LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Help - can't understand why this doesn't work

Hi,

I've got a control file which produces team workbooks - one sheet per member
of staff. It then adds in a manager template.

All this works.

The final step is to call a procedure, "PrepTheTemplate" which customises
the manager template to make it reflect the contents of the team workbook
(which it resides in). All the code is in the Batch Control workbook.

I think all the code in the "PrepTheTemplate" procedure works, but there's
one problem. No matter what I do, it inststs on executing the code on the
Batch Control workbook rather than the team one.

This has flummoxed everybody who I've been able to get to look at it, but
none of us are much good with VBA.

I'm a little desperate for a solution now as it's holding everything up.

The code is as follows: (the section that should change the context to the
team workbook is denoted by a )

Any help is very gratefully received.

Tom.



Sub PrepTheTemplate(CurrentSupervisor As String, CurrentLocation As String)

'select the correct workbook and sheet
Workbooks(CurrentLocation + " - " + CurrentSupervisor + ".xls").Activate
Sheets("Manager").Select


' Workbooks(CurrentLocation + " - " + CurrentSupervisor +
".xls").Sheets(Manager).Select

'dump the sheet names in to cells

sheetlistnumber = 1
Dim wks As Worksheet
For Each wks In Workbooks(CurrentLocation + " - " + CurrentSupervisor +
".xls").Worksheets
With Workbooks(CurrentLocation + " - " + CurrentSupervisor + ".xls")
.Sheets("Manager").Select
.Cells(sheetlistnumber + 28, 51).Value = wks.Name
.Cells(sheetlistnumber + 6, 1).Value = wks.Name
End With

sheetlistnumber = sheetlistnumber + 1
Next wks

Cells(18, 51).Value = sheetlistnumber - 1


' Fix range of pipeline chart

Worksheets("Manager").ChartObjects("Chart 1").Chart.SetSourceData _
Source:=Worksheets("Manager").Range("dPipelineChar t"), PlotBy:=ByRows

'find and replace with range of worksheets

Cells.Replace What:="a1a1a1a1:z9z9z9z9",
Replacement:=Range("BD16").Value, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False


'Clear name of manager sheet from pres area
'Range("A7").Select
'Selection.ClearContents

'nastybit

Dim WorB As Workbook
Dim SHee As Worksheet
Dim Rng As Range
Dim delRng As Range
Dim rCell As Range
Dim CalcMode As Long

Set WorB = ThisWorkbook
Set SHee = WorB.Sheets("Manager") '<<==== CHANGE
Set Rng = SHee.Range("A8:A31") '<<==== CHANGE

On Error Resume Next
Set Rng = Rng.SpecialCells(xlBlanks)
On Error GoTo XIT

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

If Not Rng Is Nothing Then
For Each rCell In Rng.Cells
If delRng Is Nothing Then
Set delRng = rCell.Resize(1, 18)
Else
Set delRng = Union(rCell.Resize(1, 18), delRng)
End If
Next rCell

If Not delRng Is Nothing Then
delRng.Delete shift:=xlUp
End If
End If
XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I don't understand why the formula doesn't work mmcap Excel Worksheet Functions 3 February 10th 07 10:58 PM
I need to understand how the IRR, NPV and FPV formulas work? Thks Juanmi Excel Worksheet Functions 1 August 15th 06 05:27 PM
I don't Understand elusiverunner Excel Worksheet Functions 6 November 25th 05 09:19 PM
Select case statement - it will not work and i dont understand why! :o( Thomas[_19_] Excel Programming 3 September 26th 05 05:14 PM
<> Scooterdog Excel Worksheet Functions 1 November 8th 04 07:56 AM


All times are GMT +1. The time now is 12:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"