Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run-time error 9 Problem


Hi all,

I've found some VBA code that appears perfect for what I want to do -
that is select a range of cells in one workbook, then copy it into
another (Report Template). This needs to be done over a large number of
workbooks, all going into 'Report Template', hence the need for the
macro.

I'm currently using the following code:

Sub CopySelection()
Dim destrange As Range
If Selection.Areas.Count 1 Then Exit Sub
Set destrange = Sheets("Report Template").Range("A" & _
LastRow(Sheets("Report Template")) + 1)
Selection.Copy destrange
End Sub

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function

Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function

...but keeping getting a 'Run-time error code '9': Subscript out of
range'.

Can anyone suggest what I'm doing wrong?

TIA,

SamuelT


--
SamuelT
------------------------------------------------------------------------
SamuelT's Profile: http://www.excelforum.com/member.php...o&userid=27501
View this thread: http://www.excelforum.com/showthread...hreadid=480836

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Run-time error 9 Problem

You don't have a sheet named "Report Template" in the activeworkbook when
you run the code. You may have one like

("Report Template ")
or
(" Report Template")

But excel can't find one named "Report Template"

--
Regards,
Tom Ogilvy


"SamuelT" wrote in
message ...

Hi all,

I've found some VBA code that appears perfect for what I want to do -
that is select a range of cells in one workbook, then copy it into
another (Report Template). This needs to be done over a large number of
workbooks, all going into 'Report Template', hence the need for the
macro.

I'm currently using the following code:

Sub CopySelection()
Dim destrange As Range
If Selection.Areas.Count 1 Then Exit Sub
Set destrange = Sheets("Report Template").Range("A" & _
LastRow(Sheets("Report Template")) + 1)
Selection.Copy destrange
End Sub

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function

Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function

..but keeping getting a 'Run-time error code '9': Subscript out of
range'.

Can anyone suggest what I'm doing wrong?

TIA,

SamuelT


--
SamuelT
------------------------------------------------------------------------
SamuelT's Profile:

http://www.excelforum.com/member.php...o&userid=27501
View this thread: http://www.excelforum.com/showthread...hreadid=480836



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run-time error 9 Problem


...........


--
SamuelT
------------------------------------------------------------------------
SamuelT's Profile: http://www.excelforum.com/member.php...o&userid=27501
View this thread: http://www.excelforum.com/showthread...hreadid=480836

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Run-time error 9 Problem

I know. Your welcome.

--
Regards,
Tom Ogilvy

"SamuelT" wrote in
message ...

.........


--
SamuelT
------------------------------------------------------------------------
SamuelT's Profile:

http://www.excelforum.com/member.php...o&userid=27501
View this thread: http://www.excelforum.com/showthread...hreadid=480836



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run-time error 9 Problem


Thanks Tom.

You're right - the code is supposed to run in a range of othe
spreadsheets and feed the data back into "Report Template".

Any ideas on how to do this?

TIA,

Samuel

--
Samuel
-----------------------------------------------------------------------
SamuelT's Profile: http://www.excelforum.com/member.php...fo&userid=2750
View this thread: http://www.excelforum.com/showthread.php?threadid=48083



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run-time error 9 Problem


Thanks Tom.

You're right - the code is supposed to run in a range of othe
spreadsheets and feed the data back into "Report Template".

Any ideas on how to do this?

TIA,

Samuel

--
Samuel
-----------------------------------------------------------------------
SamuelT's Profile: http://www.excelforum.com/member.php...fo&userid=2750
View this thread: http://www.excelforum.com/showthread.php?threadid=48083

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
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
I got this problem run-time error 1004 application defined ... Davide Blau Excel Discussion (Misc queries) 2 July 10th 06 09:27 PM
VBA VLookup Problem: Run-Time error '1004' hurlbut777 Excel Programming 4 February 5th 05 12:43 AM
"Can't Show Modally" - Run-Time Error '400' Problem Bruce B[_2_] Excel Programming 3 July 14th 03 02:01 PM


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