Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 454
Default Copy Values based on a Match Q

I have the code below that Copy-Paste Values-Transposes values in
Column D8:D33 (on sheet Input) to the row that matches the value in D6
(on sheet Input) held in Column A starting in Row 7 (on sheet YTD).

This works great except I have 35 columns in total to copy based on a
match ColA YTD. I can repeat this code 35 times, but is there a way to
incorporate a loop with the code below that will have the same effect?


Sub PostInputValues()
Application.ScreenUpdating = False
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Input")
dt = sh.Range("D6").Value
With Worksheets("YTD")
Set rng = .Range(.Cells(7, 1), .Cells(7, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "dd-mm-yy") & " was not found"
Exit Sub
End If
sh.Range("D8:D33").Copy
rng1.Offset(0, 2).PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True
Worksheets("YTD").Select
Range("C7").Select

Worksheets("Input").Select
Range("B5").Select
Application.CutCopyMode = False

End Sub
Reply
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 Cell, Paste based on a match. Pete Excel Programming 2 July 23rd 07 07:20 PM
copy rows that do not match values in dynamic range. Zebrahead Excel Programming 2 March 13th 07 06:27 PM
Copy cell values if cells match on two diff sheets dan Excel Programming 0 June 23rd 06 02:00 PM
match 2 databases based on a column with same values jasonsgoat Excel Discussion (Misc queries) 0 April 4th 06 06:35 PM
How do i compare values from two sheet and copy & paste if values match? rozb Excel Programming 0 March 5th 04 12:06 AM


All times are GMT +1. The time now is 05:50 AM.

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

About Us

"It's about Microsoft Excel"