PC Review


Reply
Thread Tools Rate Thread

concatenate cell.value

 
 
caroline
Guest
Posts: n/a
 
      27th Oct 2008
I am trying to concatenate 2 values (for instance new value in cell D4=
current value cell D4 + value Cell D3)

I get an error message 13 with this code:
For Each cell In Columns(4)
cell.Value = cell.Value & cell.Offset(0, -1).Value
Next

Any idea?
thanks
--
caroline
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      27th Oct 2008
You had Value which is a number and excel doesn't like AND (&) a number.

cell.Value = cell.Text & cell.Offset(0, -1).Text

"caroline" wrote:

> I am trying to concatenate 2 values (for instance new value in cell D4=
> current value cell D4 + value Cell D3)
>
> I get an error message 13 with this code:
> For Each cell In Columns(4)
> cell.Value = cell.Value & cell.Offset(0, -1).Value
> Next
>
> Any idea?
> thanks
> --
> caroline

 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      27th Oct 2008
Try something like:

Sub caroline()
For Each cell In Range("D1100")
cell.Value = cell.Value & cell.Offset(0, -1).Value
Next
End Sub
--
Gary''s Student - gsnu200810


"caroline" wrote:

> I am trying to concatenate 2 values (for instance new value in cell D4=
> current value cell D4 + value Cell D3)
>
> I get an error message 13 with this code:
> For Each cell In Columns(4)
> cell.Value = cell.Value & cell.Offset(0, -1).Value
> Next
>
> Any idea?
> thanks
> --
> caroline

 
Reply With Quote
 
dmoney
Guest
Posts: n/a
 
      27th Oct 2008
You are trying to concantanate using the value that you are replacing in the
same cell.

2 options

1

use a different cell to concantanate the 2 values

Sub tst()

For Each cell In Columns(5)
cell.FormulaR1C1 = "=rc[-2] & rc[-1]"
Next

End Sub

or

assign the value that is in column d to a variable and concantante col c
with the variable

HTH

"caroline" wrote:

> I am trying to concatenate 2 values (for instance new value in cell D4=
> current value cell D4 + value Cell D3)
>
> I get an error message 13 with this code:
> For Each cell In Columns(4)
> cell.Value = cell.Value & cell.Offset(0, -1).Value
> Next
>
> Any idea?
> thanks
> --
> caroline

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      27th Oct 2008
For starters..........Offset(0, -1) is C4, not D3

If you meant D3 then Offset(-1, 0)

Bur that will keep adding the contents from each cell in column D to the
next cell below to the next cell below to the next cell below...............

Gonna get a lot of content by the time you loop through column D

If you meant C4 then try this to loop through the used range in column D

Dim rng1 As Range
Range("D1").Select
Set rng1 = Range(ActiveCell, Cells(Rows.Count, _
ActiveCell.Column).End(xlUp))
For Each cell In rng1
cell.Value = cell.Value & cell.Offset(0, -1).Value
Next


Gord Dibben MS Excel MVP

On Mon, 27 Oct 2008 11:53:03 -0700, caroline
<(E-Mail Removed)> wrote:

>I am trying to concatenate 2 values (for instance new value in cell D4=
>current value cell D4 + value Cell D3)
>
>I get an error message 13 with this code:
>For Each cell In Columns(4)
>cell.Value = cell.Value & cell.Offset(0, -1).Value
>Next
>
>Any idea?
>thanks


 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      27th Oct 2008
>If you meant D3 then Offset(-1, 0)

But you could not use this on an entire column

D1 has no Offset(-1, 0)

So a range would be required like D21000


Gord


 
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
Concatenate text cell and formula cell result GoinCrazy Microsoft Excel Worksheet Functions 4 26th Nov 2008 04:27 PM
Concatenate list of cell values into one cell bony_tony Microsoft Excel Programming 3 19th Jun 2007 06:05 PM
How to concatenate a value in cell =?Utf-8?B?dWI=?= Microsoft Excel Worksheet Functions 4 29th May 2007 05:32 PM
How to concatenate a url and the value of another cell hwest13 Microsoft Excel New Users 2 3rd Jun 2005 09:11 PM
concatenate cell =?Utf-8?B?dmFsbW9udA==?= Microsoft Excel Worksheet Functions 2 11th Mar 2005 03:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:23 AM.