ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   FindNext and Copy Help (Urgent) (https://www.excelbanter.com/excel-programming/307756-re-findnext-copy-help-urgent.html)

Don Guillett[_4_]

FindNext and Copy Help (Urgent)
 
have you looked in vba HELP index for FIND? There is a good example there.

--
Don Guillett
SalesAid Software

"Lolly" wrote in message
...
My SourceData looks as follows

Measure Value


31 132
31 135
34 123
34 124
35 235

My code looks like this

Dim Rng As Range
Application.Worksheets("Sheet3").Select
Set Rng = Range("data").Find(What:="31", LookAt:=xlWhole,

LookIn:=xlValues)
If Rng Is Nothing Then
MsgBox "Data Not Found"
Exit Sub
Else
Rng.Offset(0, 1).Copy
Destination:=Application.Worksheets("Sheet1").Rang e("A2")
End If


This copies only first value of 31 in the sheet1. I want to copy all the
values corresponding to 31
In sheet1

Data should look like this

132 135 ...Till the last Occurence of value 31 is there it needs to be
copied to sheet1

If anyone could help me urgently

Thanx








--
Kittie




Andrew Smith

FindNext and Copy Help (Urgent)
 
This code is a little more complicated but works for me, only problem
is it generates an error if there are no values found. I create loop
that terminates when you get back to the original value. Please let
me know if this works for you or if you find a simpler way of
implementing:


'Find first instance and record location
Cells.Find(What:="31", after:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
firstrow = ActiveCell.Row
firstcol = ActiveCell.Column
foundlast = 0



Do While foundlast = 0 'loop till at first location again

Cells.Find(What:="31", after:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
th_row = ActiveCell.Row
th_col = ActiveCell.Column





If th_row = firstrow Then
If th_col = firstcol Then foundlast = 1

End If]




[INSERT YOUR COMMANDS HERE]



Loop


All times are GMT +1. The time now is 11:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com