Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Variable causing subscript out of range error

I am trying to saving a file based on the text name in a designated cell in
the workbook. However, with this code, I get an €śsubscript out of range€ť
error. I am running out of ideas. There must be a way to do this! Seems
to be problem with variable.


Thanks for your help.

Windows("fxRM_Update.xls").Activate

Dim bk As Workbook, bk1 As Workbook
Dim sstr As String
Dim path2 As String
path2 = ActiveWorkbook.Path

Set bk = Workbooks("fxRM_update.xls")
sstr = bk.Worksheets("lookup").Range("d39").Value
Set bk1 = Workbooks(sstr) THIS IS WHERE SUBSCRIPT ERROR OCCURS

ActiveWorkbook.SaveCopyAs filename:= bk1
'bk.saveas
'ActiveWorkbook.SaveCopyAs filename:= p & bk1
' ActiveWorkbook.SaveCopyAs filename:=path2 & "\" & bk1

A similar macro works fine:

Sub update4() 'defines user file in fxRM_Update.xls Need to insert this
everytime you reactivate fxRM_Update and want to refer back to user file.

Dim bk As Workbook, bk1 As Workbook
Dim sstr As String

Set bk = Workbooks("fxRM_update.xls")

sstr = bk.Worksheets("lookup").Range("d39").Value

Set bk1 = Workbooks(sstr)


bk1.Activate


End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Variable causing subscript out of range error

Your issue is gong to be that there is no workbook open that matches the
value sstr. Add a message box just before the line that sets the object
reference to confirm the value of sstr. You will need it to match exactly to
the name of the open workbook. Check for blank spaces and such...

sstr = bk.Worksheets("lookup").Range("d39").Value
msgbox sstr 'Check the value of the variable
Set bk1 = Workbooks(sstr) THIS IS WHERE SUBSCRIPT ERROR OCCURS
--
HTH...

Jim Thomlinson


"Andyjim" wrote:

I am trying to saving a file based on the text name in a designated cell in
the workbook. However, with this code, I get an €śsubscript out of range€ť
error. I am running out of ideas. There must be a way to do this! Seems
to be problem with variable.


Thanks for your help.

Windows("fxRM_Update.xls").Activate

Dim bk As Workbook, bk1 As Workbook
Dim sstr As String
Dim path2 As String
path2 = ActiveWorkbook.Path

Set bk = Workbooks("fxRM_update.xls")
sstr = bk.Worksheets("lookup").Range("d39").Value
Set bk1 = Workbooks(sstr) THIS IS WHERE SUBSCRIPT ERROR OCCURS

ActiveWorkbook.SaveCopyAs filename:= bk1
'bk.saveas
'ActiveWorkbook.SaveCopyAs filename:= p & bk1
' ActiveWorkbook.SaveCopyAs filename:=path2 & "\" & bk1

A similar macro works fine:

Sub update4() 'defines user file in fxRM_Update.xls Need to insert this
everytime you reactivate fxRM_Update and want to refer back to user file.

Dim bk As Workbook, bk1 As Workbook
Dim sstr As String

Set bk = Workbooks("fxRM_update.xls")

sstr = bk.Worksheets("lookup").Range("d39").Value

Set bk1 = Workbooks(sstr)


bk1.Activate


End Sub


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
Runtime Error - Subscript out of range despite On Error statement DoctorG Excel Programming 3 July 28th 06 03:56 PM
Subscript out of range error - save copy error bg18461[_16_] Excel Programming 2 June 13th 06 04:53 PM
Subscript out of range error - save copy error bg18461[_15_] Excel Programming 1 June 13th 06 04:36 PM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM
Variable-Length String causing error Q[_2_] Excel Programming 4 December 8th 03 11:31 PM


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