A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

vLookup and Line Breaking



 
 
Thread Tools Display Modes
  #1  
Old March 10th, 2010, 06:56 PM posted to microsoft.public.excel.worksheet.functions
Jon M.
external usenet poster
 
Posts: 51
Default vLookup and Line Breaking

Greetings all,
I have a worksheet where cell B8 and B10 perform a vLookup based on a data
validation in B6:

=IF(B6="","",(VLOOKUP(B6,Position,2,0)))
IF(B6="","",VLOOKUP(B6,AD_Groups,2,0))

I have the following code in place to perform a line break after each comma
in the returned value. It works great the first time, but then anytime I
change or add something to any cell in the range B1:B10 it adds another line
break to B8 and B10. Anything after B10 is fine and doesn't affect the
previous cells. I guess what I'm asking is if there is a way to alter this
code (which I found in a previous posting, just altered my range to B1) so
that it only happens if B6 is selected and changed? And only affects cells
B8 and B10, so any other cells that may have commas are unaffected?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim a As Range
Dim t As Range
Set t = Target
Set a = Range(Range("B1"), Cells(Rows.Count, 1).End(xlUp))
Dim s1 As String
Dim s2 As String
s1 = ","
s2 = s1 & Chr(10)
If Intersect(t, a) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each t In a
t.Value = Replace(t.Value, s1, s2)
Next t
Application.EnableEvents = True
End Sub

Also if I try to clear out my cells to start over, my formula's disappear and
I can't add them back. Each time I try the cell just clears itself out
again. I have to alter my range to something like A1, then I can add my
formulas again.

As always I appreciate any help I can get.
--
Jon M.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:50 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.