Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default Subscript out of Range problem Copy Cell from one workbook to anot

Hi I have a spreadsheet called MasterSheet.xls
In this sheet is a button with the code below attached. On clicking the
button it should copy cell E1 in "Mastersheet.xls" (which it does) and copy
the value into spreadsheet called "Dummy Rates.xls" under Sheet "ITS GB"
However it comes up with an Error saying 'Subscript out of Range'. If I take
out the line 'Sheets("ITS GB").Select' Then the code works but will only
paste in the active sheet.
Any ideas?

Cheers


Sub Rectangle6()
Range("E1").Select
Selection.Copy
Workbooks.Open Filename:= _
"J:\Dummy Rates.xls" _
, UpdateLinks:=3
Sheets("ITS GB").Select
Range("G5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Subscript out of Range problem Copy Cell from one workbook to anot

Hi,

Untested but try it like this. Note I think it's a bad idea to copy the
unqualified
range("E1")
You would be better qualifying that range along the lines of

Activeworkbook.sheets("Sheet1").range("E1").copy

Sub Rectangle6()
Range("E1").Copy
Workbooks.Open Filename:="J:\Dummy Rates.xls", UpdateLinks:=3
Sheets("ITS GB").Range("G5").PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"james" wrote:

Hi I have a spreadsheet called MasterSheet.xls
In this sheet is a button with the code below attached. On clicking the
button it should copy cell E1 in "Mastersheet.xls" (which it does) and copy
the value into spreadsheet called "Dummy Rates.xls" under Sheet "ITS GB"
However it comes up with an Error saying 'Subscript out of Range'. If I take
out the line 'Sheets("ITS GB").Select' Then the code works but will only
paste in the active sheet.
Any ideas?

Cheers


Sub Rectangle6()
Range("E1").Select
Selection.Copy
Workbooks.Open Filename:= _
"J:\Dummy Rates.xls" _
, UpdateLinks:=3
Sheets("ITS GB").Select
Range("G5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Subscript out of Range problem Copy Cell from one workbook to anot

Use the workbook/worksheet object as below...

Sub Rectangle6()
Dim wb As Workbook, ws As Worksheet
Set ws = ActiveSheet
Set wb = Workbooks.Open(Filename:="J:\Dummy Rates.xls", UpdateLinks:=3)
wb.Sheets("ITS GB").Range("G5") = ws.Range("E1").Value
End Sub

--OR try the below version if you dont want the user to know whats happening
in the background...(and probably update and close the workbook)

Sub Rectangle6()
Dim wb As Workbook, ws As Worksheet

Set ws = ActiveSheet
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:="J:\Dummy Rates.xls", UpdateLinks:=3)
wb.Sheets("ITS GB").Range("G5") = ws.Range("E1").Value
Application.DisplayAlerts = True
wb.Close True
Application.DisplayAlerts = False
Application.ScreenUpdating = True
End Sub


--
Jacob


"james" wrote:

Hi I have a spreadsheet called MasterSheet.xls
In this sheet is a button with the code below attached. On clicking the
button it should copy cell E1 in "Mastersheet.xls" (which it does) and copy
the value into spreadsheet called "Dummy Rates.xls" under Sheet "ITS GB"
However it comes up with an Error saying 'Subscript out of Range'. If I take
out the line 'Sheets("ITS GB").Select' Then the code works but will only
paste in the active sheet.
Any ideas?

Cheers


Sub Rectangle6()
Range("E1").Select
Selection.Copy
Workbooks.Open Filename:= _
"J:\Dummy Rates.xls" _
, UpdateLinks:=3
Sheets("ITS GB").Select
Range("G5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Subscript out of Range problem Copy Cell from one workbook to

Slight correction...

Sub Rectangle6()
Dim wb As Workbook, ws As Worksheet

Set ws = ActiveSheet
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:="J:\Dummy Rates.xls", UpdateLinks:=3)
wb.Sheets("ITS GB").Range("G5") = ws.Range("E1").Value
Application.DisplayAlerts = False
wb.Close True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub


--
Jacob


"Jacob Skaria" wrote:

Use the workbook/worksheet object as below...

Sub Rectangle6()
Dim wb As Workbook, ws As Worksheet
Set ws = ActiveSheet
Set wb = Workbooks.Open(Filename:="J:\Dummy Rates.xls", UpdateLinks:=3)
wb.Sheets("ITS GB").Range("G5") = ws.Range("E1").Value
End Sub

--OR try the below version if you dont want the user to know whats happening
in the background...(and probably update and close the workbook)

Sub Rectangle6()
Dim wb As Workbook, ws As Worksheet

Set ws = ActiveSheet
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:="J:\Dummy Rates.xls", UpdateLinks:=3)
wb.Sheets("ITS GB").Range("G5") = ws.Range("E1").Value
Application.DisplayAlerts = True
wb.Close True
Application.DisplayAlerts = False
Application.ScreenUpdating = True
End Sub


--
Jacob


"james" wrote:

Hi I have a spreadsheet called MasterSheet.xls
In this sheet is a button with the code below attached. On clicking the
button it should copy cell E1 in "Mastersheet.xls" (which it does) and copy
the value into spreadsheet called "Dummy Rates.xls" under Sheet "ITS GB"
However it comes up with an Error saying 'Subscript out of Range'. If I take
out the line 'Sheets("ITS GB").Select' Then the code works but will only
paste in the active sheet.
Any ideas?

Cheers


Sub Rectangle6()
Range("E1").Select
Selection.Copy
Workbooks.Open Filename:= _
"J:\Dummy Rates.xls" _
, UpdateLinks:=3
Sheets("ITS GB").Select
Range("G5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
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
How to keep superscript and subscript when copying formula to anot Robin Excel Discussion (Misc queries) 2 July 29th 09 09:54 PM
How can I automatically copy cell contents from one cell into anot geeeberry New Users to Excel 2 July 6th 08 10:33 AM
Subscript out of range problem Tom Ogilvy Excel Programming 0 September 15th 04 06:00 PM
Subscript out of range problem JE McGimpsey Excel Programming 0 September 15th 04 05:55 PM
Excel Macro Problem, Add-in need to work in every workbook & Error:9 Subscript out of range Burak[_2_] Excel Programming 1 October 31st 03 08:09 PM


All times are GMT +1. The time now is 04:31 PM.

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"