+ Reply to Thread
Results 1 to 2 of 2

[VBA] Indirect copy to dynamic worksheet

Hybrid View

Armitage2k [VBA] Indirect copy to... 07-02-2014, 09:38 PM
HaHoBe Re: [VBA] Indirect copy to... 07-03-2014, 12:15 AM
  1. #1
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    [VBA] Indirect copy to dynamic worksheet

    Hi,

    I am working on a way to copy data from my activeworksheet to an indirectly addressed worksheet + colum + row, according to cell data on my sheet. Problem is just that I cant seem to get it past the copy process...

    B1 is the sheet name
    D1 is the colum number
    D2 is the row number (which is always row 167).

    Sub copyscore()
    Dim IndirectSheet, IndirectColumn, IndirectRow As Object
    
    Set IndirectSheet = ActiveSheet.Range("B1")
    Set IndirectColumn = ActiveSheet.Range("D1")
    Set IndirectRow = ActiveSheet.Range("D2")
    
        With ActiveWorkbook
            .ActiveSheet.Range("I4:I101").copy
            .Sheets(IndirectSheet).Select
            .Sheets(IndirectSheet).Cells(IndirectRow, IndirectColumn).Select
            .Selection.paste
        End With
    
    End Sub
    Anyone who can help with that?

    Thank you,
    A2k

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: [VBA] Indirect copy to dynamic worksheet

    Hi, Armitage2k,

    you are setting your objects to the ActiveSheet not to the addressed one.

    Set IndirectSheet = Sheets(ActiveSheet.Range("B1").Value)
    And I would set the Range for the starting cell in one trake instead of having to set it up again from a column and a row:
    Set IndirectRow = IndirectSheet.Cells(ActiveSheet.Range("D2").Value, ActiveSheet.Range("D1").Value)
    Maybe just try
    Sub copyscore()
    
    With ActiveSheet
      Sheets(.Range("B1").Value).Cells(.Range("D2").Value, .Range("D1").Value).Resize(98, 1).Value = .Range("I4:I101").Value
    End With
    
    End Sub
    for copying over just values or
    Sub copyscore()
    
    With ActiveSheet
      .Range("I4:I101").Copy Sheets(.Range("B1").Value).Cells(.Range("D2").Value, .Range("D1").Value)
    End With
    
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy indirect validation from one worksheet to another..!
    By Rhythm089 in forum Excel General
    Replies: 0
    Last Post: 07-13-2012, 01:01 AM
  2. INDIRECT Function impact on Copy Worksheet
    By Max in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-06-2005, 04:05 AM
  3. [SOLVED] INDIRECT Function impact on Copy Worksheet
    By BG in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  4. INDIRECT Function impact on Copy Worksheet
    By BG in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  5. INDIRECT Function impact on Copy Worksheet
    By BG in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-12-2005, 11:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1