![]() |
Range.Find problem
Hello everyone,
First time poster here, looking for some help with the following code: Code:
Set dupRange = Range("B5:B33000") The next part of the code then renames the files with the new column values. The above code is called when the program tries to rename a file to a name that already exists. I then want to identify the other value (filename) and rename them both. However, the above code does not work correctly, i.e. it does not return "dup" when there is a matching value in the range. I cannot understand why this problem occurs, I've read around a lot on the forums and google, but cannot find anything that helps. I am sure it is me doing something silly. The range it is checking is populated by a large formula, I'm not sure if this could cause the problem. Sorry if I am not explaining clearly, I'm pretty new to this. For reference the entire code is below, I apologise for the messiness, it could probably be done much better. Code:
Sub List_Files() |
I am still having issues with this problem, if there is an alternative method of checking the range for a duplicate value I would be happy to use that.
Thank you for your time, Tristan |
Range.Find problem
Hello,
Ozgrid.com has a great find function (http://www.ozgrid.com/forum/showthread.php?t=27240) to return a range of cells using the Find function. You could also adapt that function to instead return a boolean if you only care about whether a duplicate exists (and don't care where the duplicate resides on the sheet). Take a look at the thread above for the Range version. I have adapted the function to return a boolean below. For example, entering: Find_Dup(Cells(r, 2), Range("B5:B33000")) would return TRUE if a duplicate value exists and FALSE otherwise. Here is that code: Function Find_Dup(Find_Item As Variant, _ Search_Range As Range, _ Optional LookIn As Variant, _ Optional LookAt As Variant, _ Optional MatchCase As Boolean) As Boolean 'Adapted from: 'http://www.ozgrid.com/forum/showthread.php?t=27240 Find_Dup = False Dim c As Range If IsMissing(LookIn) Then LookIn = xlValues 'xlFormulas If IsMissing(LookAt) Then LookAt = xlPart 'xlWhole If IsMissing(MatchCase) Then MatchCase = False With Search_Range Set c = .Find( _ What:=Find_Item, _ LookIn:=LookIn, _ LookAt:=LookAt, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=MatchCase, _ SearchFormat:=False) If Not c Is Nothing Then Find_Dup = True End If End With End Function |
I have now solved the issue.
For those interested the new code was: Code:
Dim dup As Object Quote:
|
All times are GMT +1. The time now is 03:57 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com