Find / FindNex - VBA Problem

Roque

New Member
Joined
Sep 30, 2013
Messages
25
Hi,
I have a macro that need to:
1) find all occurences in spreadsheet-1 (every occurrence is a set of 3 cells, for example B1+C1+D1
2) move this data to spreadsheet-2
3) clear this occurrence in spreadsheet-1

This is the code I tried for these steps:

Do
sheet1.activate
Set OccSearch = RangeSheet1.Find(What:=Occ, lookat:=xlWhole)
Item = Range("A" & OccSearch.Row)
OccSearch.Resize(1, 3).Select
Selection.Copy
sheet2.Activate
RangeSheet2.Find(What:=Item, lookat:=xlWhole).End(xlToRight).Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
sheet1.Activate
If OccSearch.Offset(0, 3) = "" Then
Selection.ClearContents
Else
InvSearch.Offset(0, 3).Activate
Selection.Resize(1, ActiveCell.End(xlToRight).Column).Copy
Selection.Offset(0, -3).PasteSpecial Paste:=xlPasteValues
End If
Set OccSearch = rangesheet1.FindNext(OccSearch)
Loop Until OccSearch Is Nothing

The problem I noticed is that when I run the line Selection.ClearContents it changes the value of the variable OccSearch
Is there any way to avoid this?

Thanks!
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top