• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

For loop; cell value = cell value + constant

r121a947

Member
I am trying to do something that should be quite simple, but not having any luck.

I want to loop down a column (L), first select the current line cell value, and replace that value plus a constant in the current line cell.

Any help will be greatly appreciated. Thanks.
 
I was able to piece together something that works . . .

I'm certain there is a better way to do this . . .

Thanks.

Code:
Public Sub RockSoul()
Dim lRow As Long
Dim rs As Variant


lRow = Cells(Rows.Count, 1).End(xlUp).Row

For i = 1 To lRow
Range("L" & i).Select

rs = Range("L" & i).Value
Range("L" & i).Value = rs & " R+S "

Next i

End Sub
 
r121a947
You have asked Yourself An Excel Question ...
... and next You wrote something which belongs to VBA Macros
Base Forum Rules:
eg Please post, new posts in the correct forums

Do You have a clear idea - what do You want?
 
Change references if required.
First option should be enough but if you have a real large range, the 2nd macro is faster.
Code:
Sub Maybe_A()
Dim c As Range
Application.ScreenUpdating = False
    For Each c In Range("L1:L" & Cells(Rows.Count, 12).End(xlUp).Row)
        c.Value = c.Value & " R+S"
    Next c
Application.ScreenUpdating = True
End Sub

Code:
Sub Maybe_B()
Dim a, i As Long
a = Range("L1:L" & Cells(Rows.Count, 12).End(xlUp).Row).Value
    For i = LBound(a) To UBound(a)
        a(i, 1) = a(i, 1) & " R+S"
    Next i
Range("L1").Resize(UBound(a)).Value = a
End Sub
 
Back
Top