Function VBA code doesn't work

Limone

Board Regular
Joined
Dec 20, 2018
Messages
57
Hi. I'm trying to use a code found on this site https://www.extendoffice.com/documents/excel/3269-excel-concatenate-cells-if-not-empty.html

Unfortunately, when I try to execute it gives me the "can't find project or library" error. What could be the problem? It also briefly highlights the first "n" in blue before pointing to the first line of the code. Thanks in advance for any help.

Code:
Function Concatenatecells(ConcatenateArea As Range) As String
'updateby Extendoffice 20151103
  For Each n In ConcatArea: nn = IIf(n = "", nn & "", nn & n & "/"): Next
  Concatenatecells = Left(nn, Len(nn) - 1)
End Function
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try
Code:
Function Concatenatecells(ConcatenateArea As Range) As String
   Dim n As Range, nn As String
  For Each n In ConcatenateArea: nn = IIf(n = "", nn & "", nn & n & "/"): Next
  Concatenatecells = Left(nn, Len(nn) - 1)
End Function
 
Upvote 0
Same error, now "Left" gets highlighted in blue though.
Also, I'd previously changed the code so that it would read "ConcatenateArea" instead of "ConcatArea", thinking that could be the problem since I'm working on Excel 2010. I don't know if it makes a difference though, now I've changed it back.
 
Last edited:
Upvote 0
Have a look under Tools>References...

If there's anything marked as MISSING note it's name, uncheck it, save and close the workbook, re-open and try the code again.
 
Upvote 0
Does this function work for you...
Code:
Function ConcatArea(Rng As Range) As String
  Dim Cell As Range
  For Each Cell In Rng
    If Len(Cell.Value) Then ConcatArea = ConcatArea & "/" & Cell.Value
  Next
  ConcatArea = Mid(ConcatArea, 2)
End Function
 
Upvote 0
Have a look under Tools>References...

If there's anything marked as MISSING note it's name, uncheck it, save and close the workbook, re-open and try the code again.

Thank you, that worked. What should I do about the missing object? It was the Calendar Control 2007.
 
Upvote 0
Do you use the Calendar Control in the workbook?
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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