PC Review


Reply
Thread Tools Rate Thread

append all instead of one

 
 
Maarkr
Guest
Posts: n/a
 
      16th Dec 2009
I've got this code to append cell data to the right of the selected cell

ActiveCell.Value = ActiveCell.Value & " " & ActiveCell.Offset(0, 1).Value

THis code only works for a single selected cell... not multiple cells.
I want to be able to select the entire column A (not just a single cell in
col a) or multiple cells and have all cells in B append into A.

thanks
 
Reply With Quote
 
 
 
 
Otto Moehrbach
Guest
Posts: n/a
 
      16th Dec 2009
Something like this perhaps. Otto
Sub DoIt()
Dim i As Range
For Each i In Selection
i = i & " " & i.Offset(0, 1).Value
Next i
End Sub


"Maarkr" <(E-Mail Removed)> wrote in message
news:66586E41-4DDD-4328-93E6-(E-Mail Removed)...
> I've got this code to append cell data to the right of the selected cell
>
> ActiveCell.Value = ActiveCell.Value & " " & ActiveCell.Offset(0, 1).Value
>
> THis code only works for a single selected cell... not multiple cells.
> I want to be able to select the entire column A (not just a single cell in
> col a) or multiple cells and have all cells in B append into A.
>
> thanks


 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      16th Dec 2009
Hi,

loop through the range

Sub sonic()
Dim LastRow As Long
Dim MyRange As Range, c As Range
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & LastRow)
For Each c In MyRange
c.Value = c.Value & c.Offset(, 1).Value
Next
End Sub

Mike

"Maarkr" wrote:

> I've got this code to append cell data to the right of the selected cell
>
> ActiveCell.Value = ActiveCell.Value & " " & ActiveCell.Offset(0, 1).Value
>
> THis code only works for a single selected cell... not multiple cells.
> I want to be able to select the entire column A (not just a single cell in
> col a) or multiple cells and have all cells in B append into A.
>
> thanks

 
Reply With Quote
 
Ryan H
Guest
Posts: n/a
 
      16th Dec 2009
You can try using a loop. Just adjust the code below to your applicaiton by
adjusting the Sheet name and start of range.

Option Explicit

Sub AppendCells()

Dim lngLastRow As Long
Dim rng As Range

With Sheets("Sheet1")

lngLastRow = .Cells(Rows.Count, "A").End(xlUp).Row

For Each rng In .Range("A1:A" & lngLastRow)
rng.Value = rng.Value & " " & rng.Offset(0, 1).Value
Next rng
End With

End Sub

Hope this helps! If so, click "YES" below.
--
Cheers,
Ryan


"Maarkr" wrote:

> I've got this code to append cell data to the right of the selected cell
>
> ActiveCell.Value = ActiveCell.Value & " " & ActiveCell.Offset(0, 1).Value
>
> THis code only works for a single selected cell... not multiple cells.
> I want to be able to select the entire column A (not just a single cell in
> col a) or multiple cells and have all cells in B append into A.
>
> thanks

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      16th Dec 2009
oops,

Missed the space

Sub sonic()
Dim LastRow As Long
Dim MyRange As Range, c As Range
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & LastRow)
For Each c In MyRange
c.Value = c.Value & " " & c.Offset(, 1).Value
Next
End Sub

Mike

"Mike H" wrote:

> Hi,
>
> loop through the range
>
> Sub sonic()
> Dim LastRow As Long
> Dim MyRange As Range, c As Range
> LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
> Set MyRange = Range("A1:A" & LastRow)
> For Each c In MyRange
> c.Value = c.Value & c.Offset(, 1).Value
> Next
> End Sub
>
> Mike
>
> "Maarkr" wrote:
>
> > I've got this code to append cell data to the right of the selected cell
> >
> > ActiveCell.Value = ActiveCell.Value & " " & ActiveCell.Offset(0, 1).Value
> >
> > THis code only works for a single selected cell... not multiple cells.
> > I want to be able to select the entire column A (not just a single cell in
> > col a) or multiple cells and have all cells in B append into A.
> >
> > thanks

 
Reply With Quote
 
Ryan H
Guest
Posts: n/a
 
      16th Dec 2009
Or if you wish to select the cells you wish to append use this code below.
Option Explicit

Sub AppendCells()

Dim rng As Range

For Each rng In Selection
rng.Value = rng.Value & " " & rng.Offset(0, 1).Value
Next rng

End Sub

Hope this helps! If so, click "YES" below.
--
Cheers,
Ryan


"Maarkr" wrote:

> I've got this code to append cell data to the right of the selected cell
>
> ActiveCell.Value = ActiveCell.Value & " " & ActiveCell.Offset(0, 1).Value
>
> THis code only works for a single selected cell... not multiple cells.
> I want to be able to select the entire column A (not just a single cell in
> col a) or multiple cells and have all cells in B append into A.
>
> thanks

 
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
Append query to append lots of record with range input domibud Microsoft Access Queries 7 9th May 2008 02:26 AM
INSERT SQL to append recs frm another Table, NULL DATE append 30/1 accesshar Microsoft Access VBA Modules 2 14th Jan 2008 02:00 PM
What is the easiest way to open a textfile for append or create it for text append? Wolfgang Meister Microsoft C# .NET 3 23rd May 2007 04:15 PM
Append Query in VBA - to append VBA variable values to Access tabl =?Utf-8?B?QWdlbnQgRGFnbmFtaXQ=?= Microsoft Access VBA Modules 4 1st Nov 2006 04:25 PM
Paste Append - I want to make a table of records that don't append =?Utf-8?B?Q0o=?= Microsoft Access Queries 1 5th Jul 2005 06:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:51 PM.