Prepend cell contents with adjacent cell?

W

wayne

Given two columns, A and B, what's a good way to replace the contents of each cell in B with the contents of the adjoining cell in A, a space, and then the pre-existing contents of B? e.g., if A[5] contains "1.6.2" and B[5] contains "Requirements", then how do I get B[5] == "1.6.2 Requirements" (A is values of the dotted-digits form: 1, 1.1, 1.1.1, ...)

Ideally, if A is *already* a prefix of B, don't change anything ... but I can scrub those cases manually.
 
G

GS

Given two columns, A and B, what's a good way to replace the contents
of each cell in B with the contents of the adjoining cell in A, a
space, and then the pre-existing contents of B? e.g., if A[5]
contains "1.6.2" and B[5] contains "Requirements", then how do I get
B[5] == "1.6.2 Requirements" (A is values of the dotted-digits form:
1, 1.1, 1.1.1, ...)

Ideally, if A is *already* a prefix of B, don't change anything ...
but I can scrub those cases manually.

Entering a formula in cells of col B will replace the contents. Use col
C as follows...

=A?&" "&B?

...where you need to substitute ? for row number.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
L

lhkittle

Given two columns, A and B, what's a good way to replace the contents of each cell in B with the contents of the adjoining cell in A, a space, and then the pre-existing contents of B? e.g., if A[5] contains "1.6.2" and B[5]contains "Requirements", then how do I get B[5] == "1.6.2 Requirements" (A is values of the dotted-digits form: 1, 1.1, 1.1.1, ...)



Ideally, if A is *already* a prefix of B, don't change anything ... but Ican scrub those cases manually.

If you need to keep the value after "prepending" in B, see if this does what you want.

If B value starts with a 1 or a 1. then it dismisses the task of prepending..

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then Exit Sub
If Target.Column = 2 Then
If Left$(Target, 2) = "1." Then Exit Sub
If Left$(Target, 1) = "1" Then Exit Sub
End If
Application.EnableEvents = False
Target.Value = Target.Offset(0, -1) & " " & Target.Value
Application.EnableEvents = True
End Sub
 
L

lhkittle

Given two columns, A and B, what's a good way to replace the contents of each cell in B with the contents of the adjoining cell in A, a space, andthen the pre-existing contents of B? e.g., if A[5] contains "1.6.2" and B[5] contains "Requirements", then how do I get B[5] == "1.6.2 Requirements" (A is values of the dotted-digits form: 1, 1.1, 1.1.1, ...)
Ideally, if A is *already* a prefix of B, don't change anything ... butI can scrub those cases manually.



If you need to keep the value after "prepending" in B, see if this does what you want.



If B value starts with a 1 or a 1. then it dismisses the task of prepending.



Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 1 Then Exit Sub

If Target.Column = 2 Then

If Left$(Target, 2) = "1." Then Exit Sub

If Left$(Target, 1) = "1" Then Exit Sub

End If

Application.EnableEvents = False

Target.Value = Target.Offset(0, -1) & " " & Target.Value

Application.EnableEvents = True

End Sub

Sorry, I meant to add...

Regards,
Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top