Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBA Excel 'Find' Function

Posted on 2007-04-11
8
Medium Priority
?
967 Views
Last Modified: 2013-12-25
Howdy

I'm attempting to match the strings in a specific column of worksheet A with strings in a specific column in worksheet B.  Each match found results in the entire row being copied into a third worksheet.  The number of entries in the column in worksheet A varies, so the loop would continue until whatever the VBA equivalent of EOF would be when readiing from a column.   I attempted to record a macro where I used the 'Find'/CTRL-F function.  It didn't record anything, so I'm looking for the VBA function that's tied to this action.

As always, any help is greatly appreciated.

Jason
0
Comment
Question by:cdromes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 15

Expert Comment

by:dirknibleck
ID: 18890553
you just need to do:


activesheet.columns("A").find(activesheet.range("B1"))

(replace activesheet.range("B1") with whatever you are searching on)
0
 
LVL 15

Expert Comment

by:dirknibleck
ID: 18890569
The find function returns either a range or Nothing. (Nothing if it is empty)

so

while values in B

if not activesheet.column("A").find(activesheet.range("B1")) is nothing

  copy row to third sheet

end if

wend
0
 

Author Comment

by:cdromes
ID: 18890978
Normally, if I want to select an entire row prior to copying I do something like

Rows("1294:1294").Select

In this case, I don't have the row number of the item that was found, so how do I go about marking the entire row for copying?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:dirknibleck
ID: 18890996
row = activesheet.column("A").find(activesheet.range("B1")).row
0
 

Author Comment

by:cdromes
ID: 18891163
I'm getting an error at the IF statement.  Do I need to add an '.offset' or a '.value' in order to be more specific about what's being tested?

RowCount = 1
Do
    Sheets("HiltboldRaw").Select
    If ActiveSheet.Column("A").Find(Sheets("AffyTags").Range("B1")) <> " " Then
       Sheets("AffyTags").Range("B1").Offset(RowCount, 0).Row.Select
       Selection.Copy
       Sheets("Test").Select
       Rows("RowCount:RowCount").Select
       ActiveSheet.Paste
    End If
    RowCount = RowCount + 1
Loop Until IsEmpty(Sheets("AffyTags").Range("B1").Offset(RowCount, 0).Value)
0
 
LVL 15

Expert Comment

by:dirknibleck
ID: 18891346
This:
 If ActiveSheet.Column("A").Find(Sheets("AffyTags").Range("B1")) <> " "

Has to be:

 If Not (ActiveSheet.Columns("A").Find(Sheets("AffyTags").Range("B1")) is nothing)

*note Columns not Column (that was an error in my original post)
0
 

Author Comment

by:cdromes
ID: 18892101
It ran, but nothing was copied.  There are 32 matches that I know of.  Are there issues with this:

Sheets("AffyTags").Range("B1").Offset(RowCount, 0).Row.Select
Selection.Copy

?
0
 
LVL 15

Accepted Solution

by:
dirknibleck earned 200 total points
ID: 18894928
try:

rowcount= sheets("AffyTags").range("B1").end(xldown).row


for i = 1 to rowcount

    Sheets("HiltboldRaw").Select
    If Not (ActiveSheet.Columns("A").Find(Sheets("AffyTags").Range("B1")) is nothing) Then
       Sheets("AffyTags").Rows(i).Copy
       Sheets("Test").Select
       Rows("i").Select
       ActiveSheet.Paste
    End If
next i
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question