+ Reply to Thread
Results 1 to 6 of 6

InputBox to Select Cell for Paste Special

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-26-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    286

    InputBox to Select Cell for Paste Special

    I have copied data from a selection of cells and then using one of the two sets of code to paste special the data.

    The code below allows me to select the cell to paste special but the pasting comes up with an error:
    Dim Ret As Range
        Set Ret = Application.InputBox(Prompt:="Please select a range where you want to paste", Type:=8)
        Ret.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
                         SkipBlanks:=False, Transpose:=False
    With the code below (where 1Rng is the last pre-selected cell in a column – the default paste cell) the paste works but I can’t select another cell.
    Dim strName As String
        strName = InputBox(prompt:="Type in column A cell to paste component into", _
                           Title:="Price List Paste", Default:=lRng)    ', Type:=8))
        Range(strName).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    How can I modify the code to allow for cell selection and get the paste special to work?
    Thanks Sandy

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: InputBox to Select Cell for Paste Special

    First code
    when you set the Ret, you are losing the "Selection"
    set range...then do your selection/copy

    if you must do it before hand then put it into the code itself

    Eg
    Sub test2()
        Dim rng As Range
        
        Set rng = Selection
        
        Dim Ret As Range
        Set Ret = Application.InputBox(Prompt:="Please select a range where you want to paste", Type:=8)
        
        rng.Copy
        Ret.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
                         SkipBlanks:=False, Transpose:=False
                         
    End Sub
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Contributor
    Join Date
    02-26-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    286

    Re: InputBox to Select Cell for Paste Special

    I tried to simplify the code to make it easier for the post! I am using the following code for the copy from one worksheet:
    TryAgain:
        On Error GoTo Canceled
        Set r = Application.InputBox(Prompt:="Select the cells in column A", Type:=8)
        On Error GoTo 0
        s = ""
        For Each a In r.Areas
            If a.Columns.Count <> 1 Or a.Column <> 1 Then
                MsgBox "You didn't select cells just in column A", vbOKOnly + vbExclamation, "Incorrect Selection"
                GoTo TryAgain
            End If
            s = s & a.Resize(, 15).Address & ","
        Next a
        Range(Left(s, Len(s) - 1)).Copy
    Canceled:
    I am then going to another worksheet for the paste.
    I am unsure how to work the above into your code?

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: InputBox to Select Cell for Paste Special

    Sub test()
        
        Dim Ret As Range
        Set Ret = Application.InputBox(Prompt:="Please select a range where you want to paste", Type:=8)
    
    TryAgain:
        On Error GoTo Canceled
        Set r = Application.InputBox(Prompt:="Select the cells in column A", Type:=8)
        On Error GoTo 0
        s = ""
        For Each a In r.Areas
            If a.Columns.Count <> 1 Or a.Column <> 1 Then
                MsgBox "You didn't select cells just in column A", vbOKOnly + vbExclamation, "Incorrect Selection"
                GoTo TryAgain
            End If
            s = s & a.Resize(, 15).Address & ","
        Next a
        Range(Left(s, Len(s) - 1)).Copy
        
        Ret.PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
    Canceled:
    
     
    End Sub
    i just replaced rng.copy with your whole code you had in post #3

  5. #5
    Forum Contributor
    Join Date
    02-26-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    286

    Re: InputBox to Select Cell for Paste Special

    Thanks I will give that a go tomorrow.

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,158

    Re: InputBox to Select Cell for Paste Special

    Alpine skiing combined ...
    You can also do this that way:
    Sub macro_macro()
    Dim rng As String
    Dim rng_pst As String
    Dim Ret As Range
    
        Sheet1.Select
        
    TryAgain:
        On Error GoTo Canceled
        Set Ret = Application.InputBox(Prompt:="Select the cells in column A", Type:=8) '$A$2
        
        On Error GoTo 0
        s = ""
        For Each a In Ret.Areas
            'a = $A$2
            
            If a.Columns.Count <> 1 Or a.Column <> 1 Then
                MsgBox "You didn't select cells just in column A", vbOKOnly + vbExclamation, "Incorrect Selection"
                GoTo TryAgain
            End If
            s = s & a.Resize(, 15).Address & "," 's = $A$2:$O$2,
        Next a
        
        rng = ActiveSheet.Range(Left(s, Len(s) - 1)).Address '$A$2:$O$2 - Left(s, Len(s) - 1) = $A$2:$O$2
        'target = copy to sheet 2
        Set Ret = Application.InputBox(Prompt:="Please select a range where you want to paste", Type:=8) 'Sheet2!$A$12
        rng_pst = Ret.Parent.Name 'rng_pst = Sheet2
        Sheet1.Range(rng).Copy Destination:=Ret 'But without using ".PasteSpecial"
        Sheets(rng_pst).Select
        
    Canceled:
    End Sub

+ 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. How to select all copy and paste special from IE/Chrome tab to excel using macro?
    By Jake213981 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-15-2016, 06:50 AM
  2. select and copy paste special
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2013, 09:55 AM
  3. [SOLVED] possible to paste special without having to select?
    By timtim89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-21-2012, 08:05 AM
  4. Replies: 3
    Last Post: 02-02-2012, 12:18 PM
  5. Formula works only when I paste special and select values
    By mrcois in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-23-2010, 09:22 AM
  6. Select Range Paste Special
    By additude in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 12-30-2007, 01:09 PM
  7. InputBox to select cell locations
    By Michael M in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-21-2006, 01:25 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