PC Review


Reply
Thread Tools Rate Thread

Always keep first part of text in a cell

 
 
=?Utf-8?B?TWFydGlu?=
Guest
Posts: n/a
 
      19th Apr 2007
Hi there,
I wonder if it is possible to always keep one piece of text at the beginning
of a cell.

Lets say cells in range D5 to D2000 always need to contain the text
"Financial Review: " at the beginning then followed by the user's entry. If
the cell is empty nothing should be displayed.

Cells in range D5 to D2000 are to start with empty but will be populated
with any kind of text as we go along. The user might enter "Revenue to low
according to PL". After the user has entered "Revenue to low according to
PL" is it then possible to add "Financial Review: " with a macro. The Cell
should now display "Financial Review: Revenue to low according to PL".

Any help much appreciated.

--
Regards,

Martin
 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      19th Apr 2007
Hi Martin,

Try:

'=============>>
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range
Dim rCell As Range
Const sStr As String = "Financial Review: "

Set Rng = Me.Range("D52000") '<<==== CHANGE
Set Rng = Intersect(Rng, Target)

If Not Rng Is Nothing Then
On Error GoTo XIT
Application.EnableEvents = False
For Each rCell In Rng.Cells
With rCell
If Not IsEmpty(.Value) Then
.Value = sStr & Replace(.Value, sStr, _
vbNullString, 1, 1, vbTextCompare)
End If
End With
Next rCell

XIT:
Application.EnableEvents = True
End If
End Sub
'<<=============

This is worksheet event code and should be pasted into the worksheets's code
module (not a standard module and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.

---
Regards,
Norman


"Martin" <(E-Mail Removed)> wrote in message
news:50FE2A5A-0618-490F-A246-(E-Mail Removed)...
> Hi there,
> I wonder if it is possible to always keep one piece of text at the
> beginning
> of a cell.
>
> Lets say cells in range D5 to D2000 always need to contain the text
> "Financial Review: " at the beginning then followed by the user's entry.
> If
> the cell is empty nothing should be displayed.
>
> Cells in range D5 to D2000 are to start with empty but will be populated
> with any kind of text as we go along. The user might enter "Revenue to low
> according to PL". After the user has entered "Revenue to low according to
> PL" is it then possible to add "Financial Review: " with a macro. The Cell
> should now display "Financial Review: Revenue to low according to PL".
>
> Any help much appreciated.
>
> --
> Regards,
>
> Martin



 
Reply With Quote
 
=?Utf-8?B?TWFydGlu?=
Guest
Posts: n/a
 
      19th Apr 2007
Norman,

Thank you very very much. It is working like a dream.
--
Regards,

Martin


"Norman Jones" wrote:

> Hi Martin,
>
> Try:
>
> '=============>>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim Rng As Range
> Dim rCell As Range
> Const sStr As String = "Financial Review: "
>
> Set Rng = Me.Range("D52000") '<<==== CHANGE
> Set Rng = Intersect(Rng, Target)
>
> If Not Rng Is Nothing Then
> On Error GoTo XIT
> Application.EnableEvents = False
> For Each rCell In Rng.Cells
> With rCell
> If Not IsEmpty(.Value) Then
> .Value = sStr & Replace(.Value, sStr, _
> vbNullString, 1, 1, vbTextCompare)
> End If
> End With
> Next rCell
>
> XIT:
> Application.EnableEvents = True
> End If
> End Sub
> '<<=============
>
> This is worksheet event code and should be pasted into the worksheets's code
> module (not a standard module and not the workbook's ThisWorkbook module):
>
> Right-click the worksheet's tab
> Select 'View Code' from the menu and paste the code.
> Alt-F11 to return to Excel.
>
> ---
> Regards,
> Norman
>
>
> "Martin" <(E-Mail Removed)> wrote in message
> news:50FE2A5A-0618-490F-A246-(E-Mail Removed)...
> > Hi there,
> > I wonder if it is possible to always keep one piece of text at the
> > beginning
> > of a cell.
> >
> > Lets say cells in range D5 to D2000 always need to contain the text
> > "Financial Review: " at the beginning then followed by the user's entry.
> > If
> > the cell is empty nothing should be displayed.
> >
> > Cells in range D5 to D2000 are to start with empty but will be populated
> > with any kind of text as we go along. The user might enter "Revenue to low
> > according to PL". After the user has entered "Revenue to low according to
> > PL" is it then possible to add "Financial Review: " with a macro. The Cell
> > should now display "Financial Review: Revenue to low according to PL".
> >
> > Any help much appreciated.
> >
> > --
> > Regards,
> >
> > Martin

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to cut part of a text from one cell and automatically paste itonto another cell Sonja Microsoft Excel Misc 6 17th Aug 2009 11:35 PM
copy selected part number of text from one cell into another cell orewa Microsoft Excel Misc 1 11th Apr 2008 01:30 PM
How do I include part of a cell in text (string?) in another cell? Chris Mitchell Microsoft Excel Worksheet Functions 2 25th Jun 2007 10:08 AM
Display contents of cell in another cell as part of text string? mschmidt@carolina.rr.com Microsoft Excel New Users 3 8th Jul 2006 07:44 PM
Re: countif text-string in one cell is part of text in array Bernie Deitrick Microsoft Excel Worksheet Functions 0 9th Sep 2004 04:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:34 AM.