PDA

View Full Version : Append text from adjacent cell to an existing cell for all rows in worksheet



jg_prasad
01-19-2012, 07:07 AM
Hi,
I have two columns (A, B) with header columns as "History" and "Update" respectively.
"History" header has active rows with different data in different cells.
"Update" header also has active rows with different data in different cells.

I want to insert contents of individual rows of B into it's adjacent rows of A without overwriting the existing contents of A. This should happen for all rows in the worksheet. I am looking for vba macro for this.

The resultant A (new A) should be something like this...
"TODAY(DD-MM-YYY)+B2's content+char(10)+A2's content"

Expecting it to get autopopulated for all rows in a similar fashion whenever I run macro.

Can you help.

Thanks,
Prasad

p45cal
01-19-2012, 08:29 AM
For Each cll In Range(Range("A2"), Cells(Rows.Count, "A").End(xlUp))
cll.Value = Format(Date, "dd/mm/yyyy") & " " & cll.Offset(, 1).Value & vbLf & cll.Value
Next cll
?

jg_prasad
01-23-2012, 10:58 PM
For Each cll In Range(Range("A2"), Cells(Rows.Count, "A").End(xlUp))
cll.Value = Format(Date, "dd/mm/yyyy") & " " & cll.Offset(, 1).Value & vbLf & cll.Value
Next cll
?
Thanks very much for the reply. If I have to add an if condition to check that this update should happen only if B has some content. Else don't update anything. Can we get a full vba code for this.

what is vblf ?

p45cal
01-24-2012, 02:11 AM
Thanks very much for the reply. If I have to add an if condition to check that this update should happen only if B has some content. Else don't update anything. Can we get a full vba code for this.For Each cll In Range(Range("A2"), Cells(Rows.Count, "A").End(xlUp))
If Len(cll.Offset(, 1).Value) > 0 Then cll.Value = Format(Date, "dd/mm/yyyy") & " " & cll.Offset(, 1).Value & vbLf & cll.Value
Next cll

what is vblf ?A linefeed.