Problems with a finding macro and copying a range of cells

G

Guest

The following is a copy of a post that I did a few days ago, I am having a
problem using this macro with my data. The problem is that I need this to be
used with a range of data (ie. A1:B20). This macro can only be used (to my
understanding) with one "data" cell. Is there a macro that can function like
this but copy the range A1:B20 to the destination page? Or maybe this can be
used in a loop macro. I have never used a loop macro so I do not know how to
write one. Basically this is how it needs to go.
2 pages - Input and Main
Take a specified date from cell A4 on page "Input" and find that date on
page "Main". all dates on "Main" are in row 4.
Use the found date as a reference point and copy A1:B20 to a cell range that
starts Left 2, Down 1 from the reference point.

-OLD POST-

Assumptions:
On the input sheet the date is entered into Cell A2 and the data is
enterd into cell B2.
On the Main sheet the list of dates is in column A and the data should
be inserted into column B.

Sub finder()
Dim fDate As Date
Dim fndRng As Range
Dim inpData As String

fDate = Sheets("Input").Range("A2").Value
inpData = Sheets("Input").Range("B2").Value
With Sheets("Main").Columns(1)
Set fndRng = .Find(fDate)
End With
If Not fndRng Is Nothing Then
fndRng.Offset(0, 1).Value = inpData
End If
End Sub


Hope this helps
Rowan
 
T

Tom Ogilvy

Sub CopyDataBlock()
Dim dt as Date, res as variant
Dim rng as Range
'Take a specified date from cell A4 on page "Input"
set dt = Worksheets("Input").Range("A4")
' find that date on page "Main".
' all dates on "Main" are in row 4.
res = application.Match(clng(dt), _
Worksheets("Main").Rows(4),0)
if not iserror(res) then
'copy A1:B20 to a cell range that
'starts Left 2, Down 1
set rng = worksheets("Main").Cells(5,res-2)
Worksheets("Input").Range("A1:B20").copy Destination:=rng
end if
End If
 

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