PC Review


Reply
 
 
davegb
Guest
Posts: n/a
 
      11th Dec 2007
Trying to copy a row of data from one worksheet to another, after
getting the location of the data to be copied from the user thru a
userform. But I'm getting "method range of object worksheet failed"
message.

Option Explicit
Public bHdr As Boolean
Public lTop As Long
Public rFirstData As Range
Public lLastCol As Long
Public lNumbrCol As Long


Sub Extr10L()
Dim wbCtyData As Workbook
Dim oWS As Object
Dim wsTop10List As Worksheet
Dim wsCtyData As Worksheet
Dim lFirstDataRow As Long
Dim lArea1FirstRow As Long
Dim lArea2FirstRow As Long
Dim lArea3FirstRow As Long
Dim lHdrRow As Long
Dim lFirstDataCol As Long
Dim wsTop As Worksheet
Dim rCtyDataHdr As Range

Set wsTop10List = ThisWorkbook.Worksheets("CtyLst")
Set wsCtyData = ActiveSheet
Set wbCtyData = ActiveWorkbook

'Test is Mark Top 10 workbook is active
If ActiveWorkbook.Name = ThisWorkbook.Name Then
MsgBox "You have selected the workbook that contains the macro." &
_
Chr(13) & "Please click Ok and select the correct workbook and " &
_
Chr(13) & "worksheet and restart the macro.", vbOKOnly
Exit Sub
End If

'TEST for existing sheet named "Top"
For Each oWS In wbCtyData.Sheets
If oWS.Name = "Top" Then
If MsgBox("A worksheet named Top already exists in this
workbook." _
& Chr(13) & "Please remove or rename it and run the macro
again.", _
vbOKOnly) = vbOK Then Exit Sub
End If

Next

lTop = 0
bHdr = False

uf1021Mid.Show

With rFirstData
lLastCol = .Columns(.Columns.Count).Column
End With

lFirstDataRow = rFirstData.Row
lFirstDataCol = rFirstData.Column

Set rCtyDataHdr = wsCtyData.Range(Cells(rFirstData.Row - 1,
lFirstDataCol), Cells(rFirstData.Row - 1, lLastCol))
' Create new ws "Top"
wbCtyData.Sheets.Add.Activate
ActiveSheet.Name = "Top"
Set wsTop = ActiveSheet

rCtyDataHdr.Copy Destination:=wsTop.Range(Cells(2, 1)) <----- METHOD
RANGE OF OBJECT WORKSHEET FAILED
'End If

End Sub

I thought maybe the range I copied from had to be on the activesheet
or that the range I copied to had to be on the activesheet and tried
both, but neither helped. So can someone tell me why this code isn't
running? Thanks!
 
Reply With Quote
 
 
 
 
davegb
Guest
Posts: n/a
 
      11th Dec 2007
On Dec 11, 3:03 pm, davegb <daveg...@comcast.net> wrote:
> Trying to copy a row of data from one worksheet to another, after
> getting the location of the data to be copied from the user thru a
> userform. But I'm getting "method range of object worksheet failed"
> message.
>
> Option Explicit
> Public bHdr As Boolean
> Public lTop As Long
> Public rFirstData As Range
> Public lLastCol As Long
> Public lNumbrCol As Long
>
> Sub Extr10L()
> Dim wbCtyData As Workbook
> Dim oWS As Object
> Dim wsTop10List As Worksheet
> Dim wsCtyData As Worksheet
> Dim lFirstDataRow As Long
> Dim lArea1FirstRow As Long
> Dim lArea2FirstRow As Long
> Dim lArea3FirstRow As Long
> Dim lHdrRow As Long
> Dim lFirstDataCol As Long
> Dim wsTop As Worksheet
> Dim rCtyDataHdr As Range
>
> Set wsTop10List = ThisWorkbook.Worksheets("CtyLst")
> Set wsCtyData = ActiveSheet
> Set wbCtyData = ActiveWorkbook
>
> 'Test is Mark Top 10 workbook is active
> If ActiveWorkbook.Name = ThisWorkbook.Name Then
> MsgBox "You have selected the workbook that contains the macro." &
> _
> Chr(13) & "Please click Ok and select the correct workbook and " &
> _
> Chr(13) & "worksheet and restart the macro.", vbOKOnly
> Exit Sub
> End If
>
> 'TEST for existing sheet named "Top"
> For Each oWS In wbCtyData.Sheets
> If oWS.Name = "Top" Then
> If MsgBox("A worksheet named Top already exists in this
> workbook." _
> & Chr(13) & "Please remove or rename it and run the macro
> again.", _
> vbOKOnly) = vbOK Then Exit Sub
> End If
>
> Next
>
> lTop = 0
> bHdr = False
>
> uf1021Mid.Show
>
> With rFirstData
> lLastCol = .Columns(.Columns.Count).Column
> End With
>
> lFirstDataRow = rFirstData.Row
> lFirstDataCol = rFirstData.Column
>
> Set rCtyDataHdr = wsCtyData.Range(Cells(rFirstData.Row - 1,
> lFirstDataCol), Cells(rFirstData.Row - 1, lLastCol))
> ' Create new ws "Top"
> wbCtyData.Sheets.Add.Activate
> ActiveSheet.Name = "Top"
> Set wsTop = ActiveSheet
>
> rCtyDataHdr.Copy Destination:=wsTop.Range(Cells(2, 1)) <----- METHOD
> RANGE OF OBJECT WORKSHEET FAILED
> 'End If
>
> End Sub
>
> I thought maybe the range I copied from had to be on the activesheet
> or that the range I copied to had to be on the activesheet and tried
> both, but neither helped. So can someone tell me why this code isn't
> running? Thanks!


Nevermind! I got it to work a little while after I posted.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
http://LongPathTool.com - find and delete/copy path too long filesfrom your hard drive or LAN Windows tool to copy or delete files and folderswith path too long or filename too long error. Just browse to the file andpress a button to copy or d Martin Krag Windows XP Internet Explorer 0 22nd Apr 2011 10:08 AM
http://LongPathTool.com - find and delete/copy path too long filesfrom your hard drive or LAN Windows tool to copy or delete files and folderswith path too long or filename too long error. Just browse to the file andpress a button to copy or d Martin Krag Windows XP Configuration 0 22nd Apr 2011 10:05 AM
Copy local users and groups, copy shares with security, copy homeuser folders usenet@sphere10.com Microsoft Windows 2000 Active Directory 1 17th Feb 2009 01:31 PM
Copy local users and groups, copy shares with security, copy homeuser folders usenet@sphere10.com Windows Vista General Discussion 2 17th Feb 2009 01:31 PM
EXCEL FILE a copy/a copy/a copy ....filename =?Utf-8?B?dmU=?= Microsoft Excel New Users 1 29th Sep 2005 09:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:10 AM.