Consulting

Results 1 to 4 of 4

Thread: variable not defined compile error

  1. #1

    variable not defined compile error

    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:

    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

    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
    End Sub
    Thanks in advance for any ideas on how to fix this problem!

    Steve

    cross posted on mrexcel.com:
    http://www.mrexcel.com/forum/excel-q...ml#post4048892

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hey!

    the solution posted on mrexcel forums reminds us that we dont need to select objects ("range" in your case) in order to work with them.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    instead of

    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
    use
    Sub M_snb()
      sheets("Sheet2").Range("A1:J10").Copy ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1)
    End Sub
    or
    Sub M_snb()
      ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1).resize(10,10)=sheets("Sheet2").Range("A1:J10").Value 
    End Sub

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Syntax error:
    Destination = rng1
    Should bead
    Destination:=rng1
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •