+ Reply to Thread
Results 1 to 2 of 2

macro to copy cells based on user input

Hybrid View

  1. #1
    Registered User
    Join Date
    12-03-2009
    Location
    LA, CA
    MS-Off Ver
    Excel 2003
    Posts
    3

    macro to copy cells based on user input

    how have a macro to copy a range of cells (name range) that the user specifies to a new worksheet?
    Last edited by pankaj2145; 12-03-2009 at 02:03 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: macro to copy cells based on user input

    Request is a tad vague - you don't specify how you wish to capture named range and "new worksheet" could mean create an entirely new sheet or use another sheet already created... you also need to specify what exactly you intend to copy (everything, values only (ie no formulae) etc

    At a rough guess

    Sub Example()
    Dim nm As Name, strNm As String, vData
    strNm = Application.InputBox("Enter Defined Name to Copy", Type:=2)
    On Error Resume Next
    Set nm = ThisWorkbook.Names(strNm)
    If Not nm Is Nothing Then
        vData = Evaluate(nm.RefersTo)
        Sheets.Add After:=Sheets(Sheets.Count)
        If varType(vData) = 8204 Then
            Cells(1, "A").Resize(UBound(vData, 1), UBound(vData, 2)).Value = vData
        Else
            Cells(1,"A").Value = vData
        End If
        Set nm = Nothing
    Else
        MsgBox "Computer Says No!", vbCritical, "Error"
    End If
    End Sub
    there are plenty of other approaches - the above is just one.
    Last edited by DonkeyOte; 12-03-2009 at 04:59 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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