David Phelops
asked on
Using "Find" with VBA to search through a column of Values.
Dear Experts. I have, I hope, a relatively simple problem.
I like to keep code simple and use the minimum number of lines possible, while keeping it robust.
I have attached a simple table.
I wish to find each occurence of "F" in Column 2
Having found "F" put a value in Column 7
I can do this using loop, but it seems to me that "Find" is a faster way of doing this, without looping through each line in the range.
Please can you have a look at the code in the attached file and help me find the next line.
Many thanks
David
I like to keep code simple and use the minimum number of lines possible, while keeping it robust.
I have attached a simple table.
I wish to find each occurence of "F" in Column 2
Having found "F" put a value in Column 7
I can do this using loop, but it seems to me that "Find" is a faster way of doing this, without looping through each line in the range.
Please can you have a look at the code in the attached file and help me find the next line.
Many thanks
David
Option Explicit
Sub FindAndOffset()
'This routine should find a specific value within a column and copy a corresponding value from another column in the same row.
'E.g. If a fare is "Fixed", rather than calculated, copy the fare from the "Client Fare" Column to the "Amended Fare" Column.
Dim rFixed As Range ' Set Range to find fixed fares in Column B (Column 2)
Set rFixed = Range(Cells(2, 2), Cells(1, 2).End(xlDown))
Debug.Print rFixed.Address
'If FixedFare = "F", then copy the Client Fare (Column D - Column 4) to (Column G - Column 7)
rFixed.Find(What:="F").Offset(0, 5) = rFixed.Find(What:="F").Offset(0, 2)
'Next Find?????
'I am trying to do this without using a loop. Is this possible
End Sub
FindAndOffset.xlsm
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The solution from Faustulus takes the question a step further and gives specific relevant information as how to improve code robustness - that will be far-reaching for future programming for me.
Many thanks both
David