PC Review


Reply
Thread Tools Rate Thread

Add a character to all cells in a column

 
 
glenn
Guest
Posts: n/a
 
      28th Sep 2007
Hi all

how would i go in VBA to do this:

I have a single worksheet and i have a column with heading COLOR. I do
not know what position color has in my worksheet (it could be column B,
C or any other).

I want to prepend a character "j" to all cells in the column that have a
value.

So if my column initially is like:

COLOR
==========
yellow
pink
orange


after i run the VBA script

it should be

COLOR
==========
jyellow
jpink
jorange





thank you!
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      28th Sep 2007
one way
Sub putletterinfront()
For Each c In Range("d2:d9")
If Len(Application.Trim(c)) > 1 Then c.Value = "j" & c
Next
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"glenn" <(E-Mail Removed)> wrote in message
news:fdjk5n$ncj$(E-Mail Removed)...
> Hi all
>
> how would i go in VBA to do this:
>
> I have a single worksheet and i have a column with heading COLOR. I do not
> know what position color has in my worksheet (it could be column B, C or
> any other).
>
> I want to prepend a character "j" to all cells in the column that have a
> value.
>
> So if my column initially is like:
>
> COLOR
> ==========
> yellow
> pink
> orange
>
>
> after i run the VBA script
>
> it should be
>
> COLOR
> ==========
> jyellow
> jpink
> jorange
>
>
>
>
>
> thank you!


 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      28th Sep 2007
Dim res as Variant, rng as Range
res = Application.Match("Color",Range("A1:IV1"),0)
if not iserror(res) then
set rng = Range(.Cells(2,res),.Cells(rows.count,res))
for each cell in rng.SpecialCells(xlConstants)
cell.Value = "j" & cell.Value
Next
End if

--
regards,
Tom Ogilvy


"glenn" wrote:

> Hi all
>
> how would i go in VBA to do this:
>
> I have a single worksheet and i have a column with heading COLOR. I do
> not know what position color has in my worksheet (it could be column B,
> C or any other).
>
> I want to prepend a character "j" to all cells in the column that have a
> value.
>
> So if my column initially is like:
>
> COLOR
> ==========
> yellow
> pink
> orange
>
>
> after i run the VBA script
>
> it should be
>
> COLOR
> ==========
> jyellow
> jpink
> jorange
>
>
>
>
>
> thank you!
>

 
Reply With Quote
 
Steve Yandl
Guest
Posts: n/a
 
      28th Sep 2007
Try this

_____________________________

Sub UpdateColorColumn()
Dim colRng As Range
Dim colRef As Integer
Dim topRow As Integer

For Each colRng In Rows(1).Cells
If colRng.Value = "COLOR" Then
colRef = colRng.Column
topRow = Cells(65536, colRef).End(xlUp).Row
For R = 1 To topRow
If R > 1 And Len(Cells(R, colRef).Value) > 0 Then
Cells(R, colRef).Value = "j" & Cells(R, colRef).Value
End If
Next R
End If
Next colRng

End Sub

______________________________

Steve



"glenn" <(E-Mail Removed)> wrote in message
news:fdjk5n$ncj$(E-Mail Removed)...
> Hi all
>
> how would i go in VBA to do this:
>
> I have a single worksheet and i have a column with heading COLOR. I do not
> know what position color has in my worksheet (it could be column B, C or
> any other).
>
> I want to prepend a character "j" to all cells in the column that have a
> value.
>
> So if my column initially is like:
>
> COLOR
> ==========
> yellow
> pink
> orange
>
>
> after i run the VBA script
>
> it should be
>
> COLOR
> ==========
> jyellow
> jpink
> jorange
>
>
>
>
>
> thank you!



 
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
Test if Last Character in Column of Cells is Alpha Character Benjamin Microsoft Excel Programming 6 21st Sep 2009 06:36 PM
How do I add one leading character to all of the cells in a column SShielam Microsoft Access 2 7th Aug 2009 04:11 AM
Display cells(text) in one column based on cells which are present inother column sunnykumar948@gmail.com Microsoft Excel Misc 1 12th May 2008 01:40 PM
Add the same character(s) to multiple cells in a column (or row) . =?Utf-8?B?Zmxhc2hjYXRq?= Microsoft Excel Misc 5 5th Oct 2005 04:37 PM
adding a character to all cells in one column winifred Microsoft Excel Worksheet Functions 6 16th Jul 2004 12:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:32 PM.