Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Add a character to all cells in a column

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!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Add a character to all cells in a column

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!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Add a character to all cells in a column

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" wrote in message
...
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
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
Add the same character(s) to multiple cells in a column (or row) . flashcatj Excel Discussion (Misc queries) 6 April 22nd 23 06:09 AM
search a column for a character.. nastech Excel Discussion (Misc queries) 8 October 17th 08 06:20 AM
Can column character be added? jimmy[_5_] Excel Programming 2 March 9th 07 02:47 PM
Add a character to each row in a column Aboyer Excel Discussion (Misc queries) 1 October 8th 05 12:37 AM
Column Character Bin[_2_] Excel Programming 2 August 12th 03 04:03 AM


All times are GMT +1. The time now is 01:06 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"