For Next Loop Trouble

bubbapost

Board Regular
Joined
Mar 11, 2009
Messages
116
Hello,

The code below doesn't seem to advance to the next cell. Can anynone help me?

Code:
Sub NewConcatenate()
Dim i As Long
Dim FinalRow As Long
Dim NextRow As Long
Dim rCell As Range
FinalRow = Cells(Rows.Count, ActiveCell.Column - 1).End(xlUp).Row
Set rCell = ActiveCell
NextRow = rCell.Row
For i = 2 To FinalRow
    If rCell.Value <> "" Then
        rCell.Offset(0, 1).FormulaR1C1 = "=CONCATENATE(RC[-2],"", "",RC[-1])"
        NextRow = NextRow + 1
    End If
Next i
End Sub

Thank you!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
The value of rCell is not changing inside the loop.

Try
Code:
Dim oneCell as Range

With ActiveCell.EntireColumn
    For Each oneCell in Range(.Cells(2,1), .Cells(.Rows.Count,1).End(xlup))
        With oneCell
            If .Value <> vbNullString Then
                .Offset(0,1).FormulaR1C1 = "=CONCATENATE(RC[-2],"""", """",RC[-1])"
            End If
        End With
    Next oneCell
End With

A non-looping approach might be used, but it doesn't check for the blank cells
Code:
With ActiveCell.EntireColumn
    With Range(.Cells(2,1), .Cells(.Rows.Count,1).End(xlup))
        .Offset(0,1).FormulaR1C1 = "=CONCATENATE(RC[-2],"""", """",RC[-1])"
    End With
End With

Also to get a quote mark inside a text literal, you need to double the quote (e.g. MsgBox " ""cat"" " will display "cat" )
 
Upvote 0
Re: SOLVED: For Next Loop Trouble

I think Mike's non-looping approach should work if the formula part was changed to

"=IF(RC[-1]="""","""",CONCATENATE(RC[-2],"""", """",RC[-1]))"
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top