+ Reply to Thread
Results 1 to 2 of 2

How to copy a dynamic range with VBA and paste in another workbook?

Hybrid View

cody4334 How to copy a dynamic range... 05-19-2013, 10:42 PM
JBeaucaire Re: How to copy a dynamic... 05-20-2013, 12:01 AM
  1. #1
    Registered User
    Join Date
    08-10-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    11

    How to copy a dynamic range with VBA and paste in another workbook?

    Friends, I am trying to copy a range of cells that encompass two columns and paste it into another workbook.
    The range will/could be added to at any given time so the code has to be able to go to the last cell with data. Here is the code I have so far but I cannot get it to work. Any ideas would be helpful!

    Sub Find_Performance_Log()
        Dim FindString As String
        Dim Comment As String
        Dim Rng As Range
        Application.ScreenUpdating = True
        'Comment =
        Worksheets("Submit Comment").Range("C21").Value = "Comment Date"
        Worksheets("Submit Comment").Range("D21").Value = "Comment"
        Worksheets("Submit Comment").Range("E21").Value = "Executive"
        
        FindString = Sheets("Submit Comment").Range("B14").Value
        If Trim(FindString) <> "" Then
            With Sheets("Employees").Range("A:A")
                Set Rng = .Find(What:=FindString, _
                                After:=.Cells(.Cells.Count), _
                                LookIn:=xlValues, _
                                LookAt:=xlWhole, _
                                SearchOrder:=xlByRows, _
                                SearchDirection:=xlNext, _
                                MatchCase:=False)
                If Not Rng Is Nothing Then
                    Application.Goto Rng, True
                    ActiveCell.Offset(1, 1).Select
                    'ActiveCell.Name = Comment
                    ActiveCell.End(xlDown).End(xlToRight).Copy
                    Worksheets("Submit Comment").Activate
                    Worksheets("Submit Comment").Range("C22").Paste
                   ' ActiveCell.EntireRow.Offset(1, 0).Insert
                   ' ActiveCell.Offset = Now()
                   ' ActiveCell.Offset(0, 1) = Sheets("Submit Comment").Range("D6").Value
                   ' Worksheets("Submit Comment").Activate
                   ' MsgBox "Your comment has been submitted."
                   ' Range("D6").ClearContents
                   ' Workbooks("Performance Log.xlsm").Save
                Else
                    MsgBox "No Records found on associate"
                End If
            End With
        End If
    End Sub

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to copy a dynamic range with VBA and paste in another workbook?

    There are so many ways to do this, doing it correctly is based on the standard format of the data being examined. Can you provide some exact sample data (desensitized content, of course), so we can see what your data set really looks like?

    Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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