Results 1 to 4 of 4

[SOLVED] Copy and paste text into different workbook using specified cell location

Threaded View

  1. #1
    Registered User
    Join Date
    06-21-2017
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    3

    [SOLVED] Copy and paste text into different workbook using specified cell location

    I'm trying to make a macro that will copy text from one workbook and paste it into another. However, the cell that it needs to be pasted in will differ based on the user (i.e one user may want to paste the text in Cell A1, while a different user may want to paste the text in Cell E45).

    I thought a user-friendly way of doing this would be to have a "Paste Cell Range" cell where the user could just type in which cell range they wanted their text to be pasted in, and the macro would use that cell value when determining what cell range to paste the text in.

    Normally, I would paste something using:

    Worksheets("Sheet1").Range("A1").PasteSpecial

    I was wondering what I would write to dimension a variable as the cell the user input in the excel sheet. Let's say the user specified in Cell(4 , 2) that they wanted their text to be pasted into TestPasteBook.xlsx in A1. I tried:

     Sub test()
     Dim PasteCellRange As String
     PasteCellRange = Cells(4, 2)
    
     Workbooks("TestCopyBook").Worksheets("Sheet1").Range("B6:B9").Copy
    
     Workbooks.Open "TestPasteBook.xlsx"
     Worksheets("Sheet1").Range("PasteCellRange").PasteSpecial
    
    End Sub
    The code runs when I manually replace "PasteCellRange" with "A1", but if I leave it I get a "Run-time error '1004': Application-defined or object-defined error".

    So I'm assuming that I'm declaring the variable incorrectly, but I'm not sure the correct method.

    Thanks!
    Last edited by notgoodatexcl; 06-29-2017 at 12:20 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to read a cell for the location to goto, copy, and then paste elsewhere
    By Kfrayne in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2017, 03:45 PM
  2. [SOLVED] Find specific text within workbook's name, copy and paste it to specific cell
    By axtryo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-09-2017, 02:57 AM
  3. Replies: 3
    Last Post: 08-15-2013, 01:22 PM
  4. [SOLVED] Copy and paste data into an excel generated cell location
    By BRIANHD in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-24-2013, 02:53 PM
  5. Replies: 13
    Last Post: 11-29-2012, 08:25 PM
  6. [SOLVED] Halp! Read cell for seperator, copy text, paste each segment to new workbook cell.
    By youngtusk87 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 08-07-2012, 07:38 PM
  7. Copy and Paste to location based on cell value
    By CBron12 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-15-2010, 03:02 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