variable not defined compile error

sschwant

Board Regular
Joined
Jul 31, 2008
Messages
66
I have a range that I need to copy from on ws to another. I have some code that finds the end of the rows on the second ws to paste the copied range into ...

That was working, but I had to tinker with it in order to be able to Transpose the copied range into the other ws.

Here's the original code which works:

Code:
Sub findbottom_paste()
Dim rng1 As Range
Set rng1 = ActiveSheet.Cells(Rows.Count, 1).End(xlUp) _
            .Offset(1, 0)
Worksheets("Sheet2").Range("A1:J10").Copy _
             Destination:=rng1
End Sub
And then my attempt to implement the copy paste transpose, which results in the error on this posts' title, which happens on this line: Selection.Copy Destination = rng1


Code:
Sub test()
Dim rng1 As Range
Set rng1 = ActiveSheet.Cells(Rows.Count, 1).End(xlUp) _
            .Offset(1, 0)
Application.Goto Reference:="Extract_Fields1"
Selection.Offset(0, 1).Select
Selection.Copy Destination = rng1
'Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
'Sheets("Export").Select
'Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Looking only at that, you're missing a colon:

Code:
Selection.Copy Destination[B][COLOR="#FF0000"][SIZE=3]:[/SIZE][/COLOR][/B]=rng1
 
Upvote 0
Code:
Selection.Copy Destination = rng1
should probably be
Code:
Selection.Copy Destination[COLOR="#FF0000"]:=[/COLOR]rng1

Edit: too slow at typing as beaten by Shg. Moderator can delete this post if read.
 
Upvote 0
Please don't delete this post yet.

I added the colon, but the sub is still not finished (complete). This works fine, but only if you want to paste the range as columns. I need to paste the range as a transposed range; from columns to rows.


Now I'm getting this error: "Select method of Range class failed"

Code:
Sub test()
Dim rng1 As Range
Set rng1 = ActiveSheet.Cells(Rows.Count, 1).End(xlUp) _
            .Offset(1, 0)
Application.Goto Reference:="Extract_Fields1"
Selection.Offset(0, 1).Select
Selection.Copy Destination:=rng1
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
End Sub

Please advise, thanks!!!

Steve
 
Upvote 0
Try this...

Code:
[COLOR=darkblue]Sub[/COLOR] test()
    [COLOR=green]'Copy[/COLOR]
    Range("Extract_Fields1").Offset(0, 1).Copy
    
    [COLOR=green]'Paste[/COLOR]
    ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial _
        Paste:=xlPasteAll, Transpose:=[COLOR=darkblue]True[/COLOR]
        
    Application.CutCopyMode = [COLOR=darkblue]False[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Last edited:
Upvote 0
Try this...

Code:
[COLOR=darkblue]Sub[/COLOR] test()
    [COLOR=green]'Copy[/COLOR]
    Range("Extract_Fields1").Offset(0, 1).Copy
    
    [COLOR=green]'Paste[/COLOR]
    ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial _
        Paste:=xlPasteAll, Transpose:=[COLOR=darkblue]True[/COLOR]
        
    Application.CutCopyMode = [COLOR=darkblue]False[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

AlphaFrog -

You're a life saver! Thanks, that works perfectly!

Cheers,

Steve
 
Upvote 0

Forum statistics

Threads
1,216,194
Messages
6,129,452
Members
449,509
Latest member
ajbooisen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top