Influencing a function from within a module

Rolly_Sefu

Board Regular
Joined
Oct 25, 2013
Messages
149
Hello,

I have this code line:

VBA Code:
Sheets("Mail").Range("B8:B100").Replace What:="<first name>", Replacement:=cell.Value, SearchOrder:=xlByColumns, MatchCase:=True

"<first name>" this is part of a Range for a function to combine multiple cells into 1 cell info

Code:
Function Combine(WorkRng As Range) As String
'combine entire range into one cell
'=Combine(A1:E1)
Dim Rng As Range
Dim OutStr As String
For Each Rng In WorkRng
    OutStr = OutStr & Rng.Text & Chr(13) + Chr(10)
Next
Combine = OutStr
End Function

When i edit something in the sheet, the function performs correctly.
But once the macro runs past the replace line function returns "#Value!" since the range is Nothing.

How can i fix this ?
Thank you.
 
I think , I forgot to remove my added ' to Line '.HTMLBody = Sheets("Mail").Range("B2") because get error on my PC, Please remove it.

What about vbCrLf or <br> :
VBA Code:
"Hello" & vbCrLf & "This is on a new line"
Or
VBA Code:
"Hello" & "<br>" & "Please find attached the above invoices and backup" & "<br>"
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,215,410
Messages
6,124,752
Members
449,186
Latest member
HBryant

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