Code to copy column in sheet 1 to column in sheet 2 based on matched criteria

S

skitsoni

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 find
in the target sheet. What I want to do is have it copy data to th
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'
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 Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top