Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
prefixing columns
 
Posts: n/a
Default how do i prefix a column with letters

I am deigning a catalogue and want to prefix a column with 4 letters. How can
i do this?
  #2   Report Post  
Peter Rooney
 
Posts: n/a
Default

Hi,

You could paste something like this into the code window of the worksheet in
question (NOT a normal code module)

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim NoOfCellsToFormat As Integer
NoOfCellsToFormat = Target.Value

On Error GoTo ws_exit:
Application.EnableEvents = False

If Target.Column = 1 Then
If Target.Row 4 Then
If Target.Row < 11 Then
Target.Value = "ABCD" & Target.Formula
End If
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

The example above would prefix any entry you typed into A5 to A10 with "ABCD".
You can modify the IF statements to define any range of cells you want, as I
don't imagine you'd want to prefix everything - what about field headers for
example?

Hope this helps

Pete




once you'd
"prefixing columns" wrote:

I am deigning a catalogue and want to prefix a column with 4 letters. How can
i do this?

  #3   Report Post  
Peter Rooney
 
Posts: n/a
Default

Here's a neater version that you can use to apply to a named range on your
worksheet - it's dynamic, so you don't need to keep changing the code to
refer to different rows and columns.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim ModSheet As Worksheet
Set ModSheet = ActiveWorkbook.Worksheets("PrefixEntries")

Dim ModRange As Range
Set ModRange = ModSheet.Range("ModRange")

Dim TopLeft, TopRight, BottomLeft, BottomRight As Range
Set TopLeft = ModRange(1, 1)
Set TopRight = ModRange(1, ModRange.Columns.Count)
Set BottomLeft = ModRange(ModRange.Rows.Count, 1)
Set BottomRight = ModRange(ModRange.Rows.Count, ModRange.Columns.Count)

On Error GoTo ws_exit:

Application.EnableEvents = False

If Target.Column = TopLeft.Column Then
If Target.Column <= TopRight.Column Then
If Target.Row = TopLeft.Row Then
If Target.Row <= BottomLeft.Row Then
Target.Value = "XYZ" & Target.Formula
End If
End If
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub


"prefixing columns" wrote:

I am deigning a catalogue and want to prefix a column with 4 letters. How can
i do this?

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
no row numbers or column letters DISPLAYED RagDyer Excel Discussion (Misc queries) 4 April 24th 23 03:42 AM
Return Count for LAST NonBlank Cell in each Row Sam via OfficeKB.com Excel Worksheet Functions 12 April 17th 05 10:36 PM
How do i change column headings back to letters in excel? Chris Excel Discussion (Misc queries) 2 April 14th 05 02:10 PM
How do I change a column of cells to all capital letters? morpattyjo Excel Worksheet Functions 4 March 13th 05 07:59 PM
Excel column headings from numbers to letters happygolucky Excel Discussion (Misc queries) 2 January 21st 05 06:15 PM


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

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"