Link to home
Start Free TrialLog in
Avatar of dcmathis
dcmathis

asked on

Excel search a range for a value. If it exists, then copy cells in the same row as the value

I need to search a range of cells, B10:B500, for a value V, which is a variable.  If it is found, I need to copy the values in the range FX:JX, where X is the row that V is on in the range.

So If I'm looking for the value "horse", and it appears in cell B237, I need to copy the cells in F237:J237 to another location.

I'm pulling my hair out on this one, as I'm not really a vb programmer, but I need to get this working.  Can you help?
Avatar of karunamoorthy periasamy
karunamoorthy periasamy

could you pl attach a sample excel worksheet
Why don't you do it manually by using filters?
Avatar of Roy Cox
Are you expecting multiple rows? If not use VLOOKUP or Index/Match
Avatar of dcmathis

ASKER

karunamoorthy periasamy: Please see the attached file for an example.  The query is on one sheet, named, "Query", and the data is on the next sheet, named, oddly enough, "Data".

Shabbir Rao:  It has to be within a macro, as there are many more operations being done on other sheets in this workbook.

Roy_Cox:  I"m searching a single column for a value.  When that value is found, I need to copy the contents of four columns on the same row as the found value, but not adjacent to it.

Any help would be greatly appreciated.
Book1.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Sktneer.  That works just fine.  Now I need to figure out how to integrate it with my current macro.  The way the whole thing works is that instead of a single value, several values can be put in, and then the macro creates a new sheet for each value.  There are four sheets of date, and values from each sheet are aggregated in the new sheet for the search value.  Previously, I've been using .EntireRow.Copy for each portion of the search, but the data format has been changed (not my doing), and now I need to use the .EntireRow.Copy command for the first data sheet, and then insert the four cells in the example next to the data that I already collected.  Does this make any sense?
Well the solution I provided was based on your sample file and the description in it.
Now you are talking about a completely different scenario altogether.
I suggest you should start a new question taking this solution as a starting point and provide a sample workbook in your next question with the layout as same as that of your original workbook.
Also don't forget to mock up the desired output manually that will help the answer provider to understand that what output you are trying to achieve.
Hope that makes sense.
Yeah, it makes sense.  I think I'll hold off for now, and see if I can work something up on my own.  By the time I get a manual mock-up of the existing project built and posted, the weekend will be over.  Basicaly, what I was looking for was an alternative to the .EntireRow.Copy where I could specify an offset and number of cells to copy.  Do you know if such an animal exists?
Yes that's pretty much possible.
Don't forget to post the link of your new question here itself once it is opened.
And of course you can mark this question as solved if the solution provided took care of your question described in the sample workbook.
Thanks for the help.  After looking at what I already had and your help, I determined that my logic was incorrect on this issue, and started over, or rather moved back to an earlier iteration that worked better.  Thanks!
You're welcome.