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: 79
Default referencing a workbook using string var = error9

I'm getting a subs out of range error for the following (section taken from
sub)-

For j = 1 To 4

c = "dataname" & Format(j)
If j = 1 Or j = 2 Then u = v Else u = "TOTAL DATA"
MsgBox c 'first iter gives dataname1 as i would expect
MsgBox u 'first iter gives worksheet name in v as i would expect
MsgBox Workbooks(c).Worksheets(u).Name 'generates error 9
Exit Sub
With Workbooks(c).Worksheets(u) 'generates error 9
.Cells(1, 1).Value = "p"
.Cells(1, 2).Value = "q
.Cells(1, 3).Value = "r"
.Cells(1, 4).Value = "s"
.Cells(1, 5).Value = "t"
.Cells(1, 6).Value = "u"
.Cells(1, 7).Value = "v"
.Cells(1, 8).Value = "w"
.Cells(1, 9).Value = "x"
.Range("a1:i1").Interior.Color = vbRed
End With

Next j

notes:

dataname1 through 4 is dim as string
workbooks called dataname 1 through 4 are all open
v is a string assigned previusly which is the name of the worksheet just
added to the workbooks

c,u, dim as string


msgbox stataments used to debug - c and u variables contain what i would
expect

WHY is this not working!!

Thanks

PB
 
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
copying worksheets to a new workbook without formulae referencing original workbook [email protected] Excel Programming 2 October 16th 06 07:31 PM
referencing workbook from cells in another workbook jlejehan[_3_] Excel Programming 2 May 3rd 06 03:24 PM
workbook referencing - how to! [email protected] Excel Programming 5 December 8th 05 04:42 PM
Referencing another Workbook Bill Martin -- (Remove NOSPAM from address) Excel Discussion (Misc queries) 0 April 6th 05 07:16 PM
Dynamic input for Chart gives error9 but seems to do his job to... the dude Excel Programming 0 October 17th 03 03:56 PM


All times are GMT +1. The time now is 02:48 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"