View Full Version : Solved: concantonate cells using a loop
austenr
10-12-2005, 11:56 AM
Can someone tell me if this code will work. It compiles but the result is nothing:
Sub concantonate()
Dim i As Integer
For i = 1 To 11
If Cells(i, 2).Value = "inv" Then
Cells(i, 2).value = Cells(i, 2).value & Cells(i, 3).value
End If
Next i
End Sub
Norie
10-12-2005, 12:03 PM
What's it meant to do?
What values are actually in the cells?
Have you tried stepping through it with F8?
By the way since you haven't referenced a worksheet the Cells(x,y) will refer to the currently active sheet, which may or may not be the one you want.
austenr
10-12-2005, 12:06 PM
cell (i, 3) has a value of INV and cell(i, 4) has the value of DATE I want cell (i, 3) to read INV DATE
Norie
10-12-2005, 12:29 PM
And have you tried stepping through it?
By the way in the code you have columns 2 and 3, and in your latest post columns 3 and 4 are the only one's mentioned.
austenr
10-12-2005, 12:31 PM
Thanks for the reply. I found a work around. BTW how can you loop through a range and concantonate a & b? ex a1 & b1
Norie
10-12-2005, 12:47 PM
What exactly do you mean?
Where do you want the concatenation to end up?
Dim I As Long
For I = 1 To 10
Range("C" & I) = Range("A" & I) & Range("B" & I)
Next I
austenr
10-12-2005, 12:59 PM
Thanks Norie. Solved
Bob Phillips
10-12-2005, 03:44 PM
Can someone tell me if this code will work. It compiles but the result is nothing:
Sub concantonate()
Dim i As Integer
For i = 1 To 11
If Cells(i, 2).Value = "inv" Then
Cells(i, 2).value = Cells(i, 2).value & Cells(i, 3).value
End If
Next i
End Sub
I am confused. This works fine for me.
johnske
10-12-2005, 04:39 PM
Austen, check out http://www.vbaexpress.com/kb/getarticle.php?kb_id=580 for a function to concatenate a range of cells :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.