Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Always keep first part of text in a cell

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Always keep first part of text in a cell

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("D5:D2000") '<<==== 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" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Always keep first part of text in a cell

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("D5:D2000") '<<==== 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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF cell contains part of text Supe Excel Worksheet Functions 4 May 2nd 23 07:46 PM
Get part of text in a Cell Marcha Excel Discussion (Misc queries) 10 March 11th 08 05:04 PM
find text in cell and replace it with part of the text in that ce. jules Excel Discussion (Misc queries) 3 May 3rd 07 10:18 AM
USE PART OF TEXT FROM ONE CELL IN ANOTHER Bob Excel Discussion (Misc queries) 4 December 19th 06 12:23 AM
Display contents of cell in another cell as part of text string? [email protected] New Users to Excel 3 July 8th 06 07:44 PM


All times are GMT +1. The time now is 07:44 PM.

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

About Us

"It's about Microsoft Excel"