Sheet Code not working with other workbooks

earldunning

Active Member
Joined
Nov 9, 2006
Messages
263
I have code in a sheet (not module). I create the sheet in a new workbook on the fly (within a macro) but want the new sheet to have some functionality. Having code in the copy sheet was a way I could get macros into the new sheet.

The sheet code calls another workbook and opens to a tab. Then I need to search the newly opened workbook and place a value in it.
The problem is, the sheet code does not work beyond opening it and going to the tab. The code works fine in a module but I dont have that luxery at this time.

Any help would be appreciated. Thanks

Code:
(this code is inside a sheet - not a module)
Dim ListLength As Long
Dim cntr As Integer
Dim UniqueCRID As Integer
Dim UniqueIDFound As Boolean

Workbooks.Open Password:="release1", Filename:="\\ohlewnas0240.nwie.net\claims\Release Demand Info\Release And Demand Master.xls" 'works
Sheets("ChangeReq").Select 'works
ListLength = Range("A" & Rows.Count).End(xlUp).Row [COLOR="Red"]'doesnt work - picks up sheet info not other workbook[/COLOR]
MsgBox ("ListLength = " & ListLength)
MsgBox ("UniqueID = " & UniqueCRID)
ListLength = 165
cntr = 3
Do While cntr < ListLength + 1    [COLOR="Red"]'doesnt work - searches through sheet not other workbook [/COLOR]
    'MsgBox ("addedpoperly is " & AddedProperly & "row is " & cntr)
    If Range("A" & cntr) = UniqueCRID Then
        UniqueIDFound = True
        GoTo 10
    End If
    cntr = cntr + 1
Loop
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi

You need to tell the macro that it wants to look in the other book so

ActiveWorkbook.Range.....................

HTH


Dave
 
Upvote 0
Error:
Object does not support this property or method

When I changed it to this:
ListLength = ActiveWorkbook.Range("A" & Rows.Count).End(xlUp).Row
 
Upvote 0
Opps, sorry

Activeworkbook.Activesheet.Range
 
Upvote 0
ListLength = ActiveWorkbook.ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

Same error

I also tried:
Workbooks("Release and Demand Master").Activate
&
ListLength = Workbooks("Release and Demand Master").Sheets("ChangeReq").Range("A" & Rows.Count).End(xlUp).Row


Both errored with "Subscript our of range"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,636
Members
449,043
Latest member
farhansadik

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top