UDF doesn't work on a second computer

GeeWhiz7

Board Regular
Joined
Nov 22, 2021
Messages
214
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi Folks,

Another thing I can't quite understand what Excel is doing...

I have a UDF that I think i originally found here on Mr. Excel so it was not me that wrote this skilled piece of code.
This code works perfectly fine on my desktop computer running O365 and takes a 1D range list of words and makes combinations of the words without repeats.

When i take the same file to my laptop that is also running O365 with all the same VBA references, etc, it doesn't work and i get the following error, can't find project or library.
It looks like it is because I don't have Dim rng1, Dim g, etc for example below. When I dim rng1 as Varient, Dim g as Single and any other variables, then it works.

What I struggle to understand is, why would the workbook and macros work on one computer without these and a copy of the same exact file not work on another machine?
There are other macros in other modules as well, but they are also in both copies of the workbook laptop vs. desktop.

Thank you for your insight!

1642965544652.png


When I take the exact same file to my laptop however,

VBA Code:
Public result() As Variant
 
Function Combinations(rng As Range, n As Single)
Dim b As Single
 
rng1 = rng.Value
b = WorksheetFunction.Combin(UBound(rng1, 1), n)
 
ReDim result(b, n - 1)
Call Recursive(rng1, n, 1, 0, 0)
 
For g = 0 To UBound(result, 2)
     result(UBound(result, 1), g) = ""
Next g
 
Combinations = result
 
End Function


Function Recursive(r As Variant, c As Single, d As Single, e As Single, h As Single)
Dim f As Single
 
For f = d To UBound(r, 1)
     
        result(h, e) = r(f, 1)
     
        If e = (c - 1) Then
                 
            For g = 0 To UBound(result, 2)
                result(h + 1, g) = result(h, g)
            Next g
            h = h + 1
        Else
            Call Recursive(r, c, f + 1, e + 1, h)
        End If
     
Next f
     
End Function
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Add Dim rng1 as Variant

Bye
Thanks Anthony47, yes Dim’ing rng1 and g works which I figured out. What’s weird is I did not delete them from the original file when making a copy, yet in the copy they were gone. I dunno, maybe I did something by accident that got rid of them. Now that I think about it, I was using input director to control both computers so maybe something got messed up when I was switching back and forth.
 
Upvote 0
Are you sure they were originally dimmed? In most of the cases it's not necessary (although it is wise always declaring the variables used), but in some cases Excel interprets "rng1" (and similar notations) as "cell rng1", the Dim forces treating it as a variable

Bye
 
Last edited:
Upvote 0
Are you sure they were originally dimmed? In most of the cases it's not necessary (although it is wise always declaring the variables used), but in some cases Excel interprets "rng1" (and similar notations) as "cell rng1", the Dim forces treating it as a variable

Bye
I looked at the original file and you’re right they were not dimmed. So I guess it brings me back to why in the original file the dim is not there and it works but in the copy on a different computer it does not. Will keep tinkering with it and hopefully get it working on the second machine.
 
Upvote 0

Forum statistics

Threads
1,214,618
Messages
6,120,544
Members
448,970
Latest member
kennimack

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