Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Prefix macro
I deal with the same problem all the time. I would like to create
macro for a colum of data that would allow me to insert a custom character text prefix to the data. For example in Col A the cells are populated with a Part Number i cell A1= 100-600125, cell A2 = 500-235487, cell A3 = 547-255684, etc. I would like to add a prefix to all of the cells in the colum ie "PRE- so that the results would be each cell has the prefix added to it, i cell A1 = PRE-100-600125, cell A2 = PRE-500-235487, etc. I hope this is clear. Thanks -- Message posted from http://www.ExcelForum.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Prefix macro
|
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Prefix macro
Sub insertprefix()
Application.ScreenUpdating = False Application.Calculation = xlManual Dim cell As Range Dim myPrefix As String myPrefix = "'" myPrefix = InputBox("Supply prefix character(s)", "Supply prefix" myPrefix) For Each cell In Intersect(Selection, ActiveSheet.UsedRange) If Len(Trim(cell)) 0 Then _ cell.Formula = myPrefix & cell.Text Next cell Application.Calculation = xlAutomatic 'xlCalculationAutomatic Application.ScreenUpdating = False End Su -- Message posted from http://www.ExcelForum.com |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Prefix macro
Ted
Here's a generic macro that allows you to choose to add inputted text left or right of existing data. Sub Add_Text() Dim cell As Range Dim moretext As String Dim thisrng As Range On Error GoTo endit whichside = InputBox("Left = 1 or Right =2") Set thisrng = Range(ActiveCell.Address & "," & Selection.Address) _ .SpecialCells(xlCellTypeConstants, xlTextValues) moretext = InputBox("Enter your Text") If whichside = 1 Then For Each cell In thisrng cell.Value = moretext & cell.Value Next Else For Each cell In thisrng cell.Value = cell.Value & moretext Next End If Exit Sub endit: MsgBox "only formulas in range" End Sub Gord Dibben Excel MVP On Tue, 6 Jul 2004 09:57:36 -0500, TedL wrote: I deal with the same problem all the time. I would like to create a macro for a colum of data that would allow me to insert a custom 4 character text prefix to the data. For example in Col A the cells are populated with a Part Number ie cell A1= 100-600125, cell A2 = 500-235487, cell A3 = 547-255684, etc. I would like to add a prefix to all of the cells in the colum ie "PRE-" so that the results would be each cell has the prefix added to it, ie cell A1 = PRE-100-600125, cell A2 = PRE-500-235487, etc. I hope this is clear. Thanks. --- Message posted from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Prefix | Excel Discussion (Misc queries) | |||
omit the ns1: prefix | Excel Discussion (Misc queries) | |||
SUM without prefix | Excel Discussion (Misc queries) | |||
cell prefix | Excel Discussion (Misc queries) | |||
Prefix | Excel Worksheet Functions |