View Single Post
  #1   Report Post  
skitsoni skitsoni is offline
Junior Member
 
Location: Northern NJ
Posts: 1
Default Code to copy column in sheet 1 to column in sheet 2 based on matched criteria

Hello all,

I have a fairly simple code below that's missing one critical step. Currently, it wants to copy the data to the first blank column it finds in the target sheet. What I want to do is have it copy data to the column in the target sheet that matches the range in the source sheet. So, if the source sheet is identified as the "June" month column, I'd like the data to be copied to "June" month column in the target sheet. Can anyone help out....thanks,
Steve

Sub CopyDataToPlan()
Dim LMonth As String
Dim LRow As Integer
Dim LFound As Boolean
'Retrieve date value to search for
LDate = Sheets("Month & YTD vs. Budget").Range("E10").Value
Sheets("Monthly Trend").Select
'Start at Row 15
LRow = 15
LFound = False
While LFound = False
'Found match in row 15
If Cells(15, LRow) = LMonth Then
'Select values to copy from "Month & YTD vs. Budget" sheet
Sheets("Month & YTD vs. Budget").Select
Range("C20:C188").Select
Selection.Copy
'Paste onto "Monthly Trend" sheet
Sheets("Monthly Trend").Select
Cells(17, LRow).Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
LFound = True
MsgBox "The data has been successfully copied."
'Continue searching
Else
LRow = LRow + 1
End If
Wend
On Error GoTo 0
Exit Sub
Err_Execute:
MsgBox "An error occurred."

End Sub