Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Pat Pat is offline
external usenet poster
 
Posts: 122
Default Linking workbooks

I use the following code to run within a workbook.

Private Sub Print_Click()
' retail sales
Calculate
Selection.AutoFilter Field:=10
Selection.AutoFilter Field:=11
Dim sProd As String
Dim icol As Long
Dim rng As Range
Dim rng1 As Range
Dim rng2 As Range, Target As Range
Dim res As Variant
Set rng = Worksheets("ControlCentre").Range("BH30")
res = Application.Match(ActiveSheet. _
Range("W2").Value, rng, 0)
If Not IsError(res) Then
icol = rng(res).Column
Else
MsgBox "Retail sale not matched"
Exit Sub
End If
With ActiveSheet
Set rng1 = Nothing
On Error Resume Next
Set rng1 = .Range("L24:L800"). _
SpecialCells(xlConstants, xlNumbers)
On Error GoTo 0
If rng1 Is Nothing Then
MsgBox "No Quantities in Retail sale"
Exit Sub
End If
End With

For Each Target In rng1
sProd = Target.Parent.Cells(Target.Row, 6)

res = Application.Match(sProd, _
Worksheets("ControlCentre").Range("C77:C1000"), 0)
If Not IsError(res) Then
With Worksheets("ControlCentre")
If IsNumeric(Target.Value) Then
Set rng2 = .Cells(res + 76, icol)
rng2.Value = rng2.Value + Target.Value
End If
End With
Else
MsgBox "Product Not found: " & sProd
End If
Next

Selection.AutoFilter Field:=12, Criteria1:="<"
'Selection.AutoFilter Field:=11

Worksheets("ControlCentre").Calculate
Calculate

End Sub

I have thus moved the sheet to a new workbook and kept the link. What I want
to do is run the code from the new workbook to the old workbook. The code
stops at the line:

Set rng = Worksheets("ControlCentre").Range("BH30")

Anyone familar with all of this?
Pat


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Linking workbooks

Pat


I have thus moved the sheet to a new workbook and kept the link. What
I want to do is run the code from the new workbook to the old
workbook. The code stops at the line:

Set rng = Worksheets("ControlCentre").Range("BH30")


If you use Worksheets without qualifying it with a Workbook object, it will
assume you mean the activeworkbook (depending on where the code is). If
you're getting a subscript out of range error, it means that there is no
worksheet called ControlCentre in that workbook. To fix, qualify with a
specific workbook

Set rng =
Workbooks("Otherbook.xls").Worksheets("ControlCent re").Range("BH30")

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com


  #3   Report Post  
Posted to microsoft.public.excel.programming
Pat Pat is offline
external usenet poster
 
Posts: 122
Default Linking workbooks

Thank you for that and also the link to your homepage.

Cheers

"Dick Kusleika" wrote in message
...
Pat


I have thus moved the sheet to a new workbook and kept the link. What
I want to do is run the code from the new workbook to the old
workbook. The code stops at the line:

Set rng = Worksheets("ControlCentre").Range("BH30")


If you use Worksheets without qualifying it with a Workbook object, it

will
assume you mean the activeworkbook (depending on where the code is). If
you're getting a subscript out of range error, it means that there is no
worksheet called ControlCentre in that workbook. To fix, qualify with a
specific workbook

Set rng =
Workbooks("Otherbook.xls").Worksheets("ControlCent re").Range("BH30")

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com




Reply
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
Linking workbooks Russell Excel Discussion (Misc queries) 0 December 17th 09 09:53 AM
linking many workbooks [email protected] Excel Discussion (Misc queries) 6 September 13th 08 02:42 PM
linking workbooks Pennywis1 Excel Worksheet Functions 2 January 26th 07 08:30 PM
linking to other workbooks Hervinder Excel Discussion (Misc queries) 1 June 14th 06 03:52 PM
linking workbooks susie Excel Discussion (Misc queries) 2 August 17th 05 09:03 PM


All times are GMT +1. The time now is 04:08 AM.

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

About Us

"It's about Microsoft Excel"