LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Data from one sheet to many based on column A Steve[_4_] Excel Programming 7 March 24th 08 06:32 PM
Help: auto-copy entire rows from 1 sheet (based on cell criteria) to another sheet. bertbarndoor Excel Programming 4 October 5th 07 04:00 PM
Copy rows to another sheet. Criteria = cells in column H is not em Henrik Excel Programming 0 May 10th 07 03:12 PM
copy to another sheet based on column value Mike Excel Programming 4 March 5th 05 12:50 AM
Cut rows from one sheet into multiple sheets based on a criteria in first column pepino13 Excel Programming 1 September 11th 03 09:52 PM


All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"