View Single Post
 
Old 11-27-2018, 06:30 PM
trevorc trevorc is offline Windows 7 32bit Office 2013
Competent Performer
 
Join Date: Jan 2017
Posts: 174
trevorc will become famous soon enoughtrevorc will become famous soon enough
Default Copy & paste 2 ranges of cells

Hi Again,
Currently trying to setup some code for when I enter a customer name the code looks for an existing name in the list and copies 2 ranges of cells from the same row, and pastes them into the new row being created. below code does find the value and returns the row number for the copy selection, I originally had it do a copy of both ranges together but when pasting that it crashed excel, so I separated them in to 2 copy and paste operations. the code crashes on the second line or pastes the data starting at Column M, is it something to do with Worksheet_SelectionChange?
Any guide in the right direction would help out thanks.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Old_Value
Old_Value = Target.Value
With Sheets("Customer").Range("H4:H5000")
    Set C = .Find(Old_Value, LookIn:=xlValues)
    If Not C Is Nothing Then
    t = C.Row
        Sheets("Customer").Range("I" & t & ":L" & t).Copy
        ActiveSheet.Paste
        Sheets("Customer").Range("Y" & t & ":AH" & t).Copy
        ActiveSheet.Paste
    End If
End With
End Sub
Reply With Quote