VBA Help

mduntley

Board Regular
Joined
May 23, 2015
Messages
139
Office Version
  1. 365
Platform
  1. Windows
I have a VBA that create a custom Vlookup code, but whenever it generates a line at the beginning of the result. Can anyone help me?


Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long)
'Update 20150310
For Each rng In pWorkRng
If rng = pValue Then
xResult = xResult & vbNewLine & rng.Offset(0, pIndex - 1)
End If
Next
MYVLOOKUP = xResult
End Function
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Does deleting & vbNewLine & work?


I add the vbNewLine because I am gathering all date and I want the result in separate rows, but in the same cell. But when it does that the first line has a enter in.
 
Upvote 0
Hi, try changing the last line before End Function to:

Code:
MYVLOOKUP = Mid(xResult, 2)
 
Upvote 0
Hi, try changing the last line before End Function to:

Code:
MYVLOOKUP = Mid(xResult, 2)


Tried that and it didn’t delete the space at the top of the cell. Only add a blank line at the bottom
 
Upvote 0
Tried that and it didn’t delete the space at the top of the cell. Only add a blank line at the bottom

Hi, sorry - try:

Rich (BB code):
MYVLOOKUP = Mid(xResult, 3)

Note, you may need to manually adjust the row height as appropriate.
 
Upvote 0
How do I get that guide text box under my formula? If you don’t understand, go to excel and do a if formula and a pop up box appear
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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