How to do this for example:
In A1 i enter "john", and when i enter "john" the cell automatically adds prefix "long_" so final text says "long_john"
How to do this for example:
In A1 i enter "john", and when i enter "john" the cell automatically adds prefix "long_" so final text says "long_john"
Depending on the number of variations you have you could use a Custom Format, however, I suspect you probably have more than one prefix.
What are the other prefixes you intend to you use ?
Have you considered creating Defined Names, eg:
Name: John
RefersTo: long_john
In native XL if you type
=john
the cell will display long_john
If that's not viable for you you will need to consider using VBA.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Evey cell in column is different but prefix is the same. Word needs to be this way:
"R1" - prefix
"something" - word entered in cell
and final result "R1something"
If you're happy to just use a "mask" then you can apply a Custom Format to the necessary range of: "R1"@
Whenever a value (say Apple) is entered into this column (say Col A) the value will appear as R1Apple.
However it's very important to note that though the R1 prefix appears & prints it does not actually exist in the cell ... the underlying value remains "Apple" (eg LEFT(A1;1) = "A" not "R")
I need it existing in the cell
So i need VBA for this? How to write a program for this and how to use it, etc. i'm beginner in this.
Assuming the values are entered manually then you can use the Worksheet_Change event.
Below is a basic example:
In the above a prefix of R1 is added to cells changed in Column A, X1 for Column B & Y1 for Column C.![]()
Private Sub Worksheet_Change(ByVal Target As Range) Dim xlCalc As XlCalculation Dim rngColumn As Range, rngInterest As Range Dim strPrefix As String If Target(1).Value = "" Then Exit Sub On Error GoTo ExitPoint With Application xlCalc = .Calculation .Calculation = xlCalculationManual .EnableEvents = False .ScreenUpdating = False End With For Each rngColumn In Target.Columns Set rngInterest = Intersect(Target, rngColumn) Select Case rngColumn.Column Case 1 strPrefix = "R1" Case 2 strPrefix = "X1" Case 3 strPrefix = "Y1" Case Else strPrefix = "" End Select rngInterest = strPrefix & rngInterest(1).Value Set rngInterest = Nothing Next rngColumn ExitPoint: With Application .Calculation = xlCalc .EnableEvents = True .ScreenUpdating = True End With End Sub
To apply - from native XL - right click on tab containing values - select View Code and paste above into resulting window.
Macros must be enabled and in 2007 and beyond file must be saved in Macro compliant type - eg .xlsm
(obviously the above does not take into account the possibility that a changed cell already has the prefix applied)
thanks! this will help.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks