PC Review


Reply
Thread Tools Rate Thread

Counts of Find/Copy Lines

 
 
1clncc
Guest
Posts: n/a
 
      20th Jun 2007

The below would search in the current worksheet rows containing myStr
then pasting those rows into another sheet ("5".

************************************************************

myStr = InputBox("Enter word to be searched")
If myStr = "" Then Exit Sub

Find_Range(myStr, Range("Eng_Name"), LookIn:=xlValues, LookAt:=
xlPart, MatchCase:=True).EntireRow.Copy Range("Sheet5!
D65536").End(xlUp).Offset(1, 0).EntireRow

*****************************************************

1) how to set counter in the find/paste operations to find out the
number of lines being pasted into sheet(5)?

2) then select those pasted lines.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      21st Jun 2007
Try this code and see if it does what you want. Let me know how it goes.

Sub Find_And_Copy()

Dim FindRange As Range
Dim myStr As String
Dim firstFind As String
Dim c As Range
Dim countCopies As Integer
Dim pasteAddress As String

myStr = InputBox("Enter word to be searched")
If myStr = "" Then Exit Sub

'NOTE: Adjust the range here to suit your
'search range.
Set FindRange = Worksheets(1).Range("d1:d16")

With FindRange

Set c = .Find(What:=myStr, _
LookIn:=xlFormulas, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If Not c Is Nothing Then
countCopies = 0
firstFind = c.Address

Do
'NOTE: when pasting an entire row
'it must start from column A otherwise
'an error occurs because it will not
'fit across the worksheet
c.EntireRow.Copy Destination:= _
Range("Sheet5!A65536 ").End(xlUp).Offset(1, 0)

countCopies = countCopies + 1

Set c = .FindNext(c)

Loop While Not c Is Nothing And _
c.Address <> firstFind
End If
End With

'Select copied rows
countCopies = countCopies - 1
Sheets("Sheet5").Select
Range("Sheet5!A65536 ").End(xlUp).Select
Range(ActiveCell, ActiveCell.Offset(-countCopies, 0)) _
.EntireRow.Select

End Sub

Regards,

OssieMac


"1clncc" wrote:

>
> The below would search in the current worksheet rows containing myStr
> then pasting those rows into another sheet ("5".
>
> ************************************************************
>
> myStr = InputBox("Enter word to be searched")
> If myStr = "" Then Exit Sub
>
> Find_Range(myStr, Range("Eng_Name"), LookIn:=xlValues, LookAt:=
> xlPart, MatchCase:=True).EntireRow.Copy Range("Sheet5!
> D65536").End(xlUp).Offset(1, 0).EntireRow
>
> *****************************************************
>
> 1) how to set counter in the find/paste operations to find out the
> number of lines being pasted into sheet(5)?
>
> 2) then select those pasted lines.
>
>

 
Reply With Quote
 
1clncc
Guest
Posts: n/a
 
      21st Jun 2007
Checked, it looks good. Thanks.


 
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
How do I copy exact page counts in Excel? Lilly216 Microsoft Excel Worksheet Functions 0 29th Aug 2008 05:00 PM
Find date, create new workbook, copy lines with same dates in column H littleme Microsoft Excel Programming 2 23rd Aug 2007 05:07 PM
Sub to copy only result lines within formula range, omit null string lines Max Microsoft Excel Programming 4 15th Jul 2007 04:21 AM
Copy and Paste at set Row counts =?Utf-8?B?SmF2eUQ=?= Microsoft Excel Programming 3 10th Sep 2004 10:02 AM
macro that counts lines with certain color Philipp Oberleitner Microsoft Excel Programming 2 15th Jun 2004 02:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:19 PM.