PC Review


Reply
Thread Tools Rate Thread

Code help - search / copy-paste

 
 
Anthony
Guest
Posts: n/a
 
      4th Aug 2008
Hi all,

being a bit of a novice and getting lots of help from this site I have tried
to write my own code, but as I am getting errors with it, I thought I would
ask for help....again !

Basically I want some code to search through column D of sheet
ReportDatabase for the date shown in cell D2 of sheet1.
Once this date is matched copy that row A:C and paste into row2 of the
DisplayReport sheet

any help appreciated
 
Reply With Quote
 
 
 
 
Office_Novice
Guest
Posts: n/a
 
      4th Aug 2008
Sub DoTonysStuff()
Dim ReportDBSheet As Worksheet
Dim DisplayReport As Worksheet
Dim FoundCell As Range
Dim SearhCell As Range
Dim SearchRange As Range
Dim FoundRange As Range
Dim x
Set ReportDBSheet = ActiveWorkbook.Worksheets(1)
Set DisplayReport = ActiveWorkbook.Worksheets(2)
Set SearhCell = ReportDBSheet.Range("D2")
Set SearchRange = ReportDBSheet.Range("D")
Set FoundCell = SearchRange.Find(What:=SearhCell.Value, LookIn:=xlValues)
x = 1

For Each FoundCell In SearchRange
If FoundCell = SearhCell Then
FoundCell.Copy Destination:=DisplayReport.Cells(x, 1)
x = x + 1
End If
Next
End Sub
This might take a little modifying but try:



"Anthony" wrote:

> Hi all,
>
> being a bit of a novice and getting lots of help from this site I have tried
> to write my own code, but as I am getting errors with it, I thought I would
> ask for help....again !
>
> Basically I want some code to search through column D of sheet
> ReportDatabase for the date shown in cell D2 of sheet1.
> Once this date is matched copy that row A:C and paste into row2 of the
> DisplayReport sheet
>
> any help appreciated

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      4th Aug 2008
This is untested:

Sub SeachnPaste()
Dim c As Range, myRange As Range, lr As Long
lr = ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row
myRange = ActiveSheet.Range("D3" & lr)
For Each c In myRange
If c.Value = Range("D2").Value Then
Range("A" & c.Row & ":C" & c.Row).Copy _
Sheets("DisplayReport").Range("A2")
End If
Next
End Sub

"Anthony" wrote:

> Hi all,
>
> being a bit of a novice and getting lots of help from this site I have tried
> to write my own code, but as I am getting errors with it, I thought I would
> ask for help....again !
>
> Basically I want some code to search through column D of sheet
> ReportDatabase for the date shown in cell D2 of sheet1.
> Once this date is matched copy that row A:C and paste into row2 of the
> DisplayReport sheet
>
> any help appreciated

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      4th Aug 2008
Your write up makes it sound like there will be only one date in Column D on
the ReportDatabase worksheet that will match the date in D2 on Sheet1. If
that is the case, this code should do what you want...

Sub FindSingleDate()
Dim C As Range
With Worksheets("ReportDatabase")
Set C = .Columns("D").Find( _
What:=Worksheets("Sheet1").Range("D2").Value, _
After:=Range("D1"), LookAt:=xlWhole, LookIn:=xlValues)
If Not C Is Nothing Then
C.Offset(0, -3).Resize(1, 3).Copy .Range("A2")
End If
End With
End Sub

Rick


"Anthony" <(E-Mail Removed)> wrote in message
news:A966C2D0-F790-4DC8-9E4F-(E-Mail Removed)...
> Hi all,
>
> being a bit of a novice and getting lots of help from this site I have
> tried
> to write my own code, but as I am getting errors with it, I thought I
> would
> ask for help....again !
>
> Basically I want some code to search through column D of sheet
> ReportDatabase for the date shown in cell D2 of sheet1.
> Once this date is matched copy that row A:C and paste into row2 of the
> DisplayReport sheet
>
> any help appreciated


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search, copy and paste help rlouhing@gmail.com Microsoft Excel Misc 0 15th Jun 2007 02:48 AM
VB Code to search,copy,paste and stop at blank row! =?Utf-8?B?QW50aG9ueQ==?= Microsoft Excel Programming 8 27th Feb 2007 04:14 AM
VBA-code for search,copy and paste =?Utf-8?B?VFVOR0FOQSBLVVJNQSBSQUpV?= Microsoft Excel Misc 0 12th Dec 2005 12:40 PM
Search-Copy and Paste-code Bourbon Microsoft Excel Programming 0 28th Jan 2004 07:54 PM
Search/copy/paste Macro mjwillyone Microsoft Excel Programming 2 27th Dec 2003 07:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:04 PM.