VBA Code Question

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
960
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I'm using the following Function below which works perfectly.

The only quirk is that when I click a Toolbar I created on another worksheet to sort 2 columns of data and then go to the original worksheet the cells that contain this formula change to #VALUE in the selected cells that contain the Function below.

I wanted to ask what may be causing the #VALUE to appear. The Function worked perfectly fine until I clicked a Toolbar in another worksheet.

Function Nth_Occurrence(range_look As Range, find_it As String, occurrence As Long, offset_row As Long, offset_col As Long)

Dim lCount As Long

Dim rFound As Range



Set rFound = range_look.Cells(1, 1)

For lCount = 1 To occurrence

Set rFound = range_look.Find(find_it, rFound, xlValues, xlWhole)

Next lCount

Nth_Occurrence = rFound.Offset(offset_row, offset_col)

End Function
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,214,653
Messages
6,120,756
Members
448,990
Latest member
Buzzlightyear

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