Solved

find method vba

Posted on 2014-03-28
6
242 Views
Last Modified: 2014-03-28
I have the following code

If IsError(Range(Cells(y, "A"), Cells(y, x - 1)).Find(what:=Cells(y, x).Value)) Then

Else
GoTo INI
End If

I want to identify when range.find not found nothing, but always  go to the else :goto INI, any idea?
0
Comment
Question by:joyacv2
  • 3
  • 3
6 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 39962383
I'd do something like this

on error resume next

set rgFound=Range(Cells(y, "A"), Cells(y, x - 1)).Find(what:=Cells(y, x).Value)) 

if err<>0 then
msgbox "error happened"
 err.clear
else
msgbox "all is well"
end if

on error goto 0

Open in new window

0
 
LVL 1

Author Comment

by:joyacv2
ID: 39962428
Hi,

where is the goto ini statement?
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39962461
Put it in the else part
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:joyacv2
ID: 39962473
Hi,

not working, enters in a infinite loop. Any other idea?

there is a loop running, i need to verify in the cells before the cells(y,x) before to enter the number, ensuring the number doesn't repeat
0
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 39962490
You can use application.worksheetfunction.countif(range, value) >0 to check if its already been entered rather than do a range.find
0
 
LVL 1

Author Closing Comment

by:joyacv2
ID: 39962499
the perfect solution!!!!! Thanks!!!!
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

778 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