Help with offset coding

MarkRCC

New Member
Joined
May 22, 2017
Messages
46
Hello All,

I'm trying to do a simple module to save the results of a calculator (in excel of course) in a list.
The code I am using is

Code:
Sub SaveResult()    
    Dim lRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Calculator")
    lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    With ws
        .Cells(lRow, 8).Value = "Converted"
        .Cells(lRow, 9).Value = Range("C5").Value
        .Cells(lRow, 10).Value = Range("C10").Value
        .Cells(lRow, 11).Value = "to"
        .Cells(lRow, 12).Value = Range("C15").Value
        .Cells(lRow, 13).Value = Range("E10").Value
    End With
End Sub

It correctly places the values where I want them, but any subsequent values are instead replacing the original saved values. I suspect the error is in the
Code:
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
part, but I'm not sure.

Thanks!
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Maybe
Code:
lRow = ws.Cells(Rows.Count, [COLOR=#ff0000]8[/COLOR]).End(xlUp).Offset(1, 0).Row
 
Upvote 0
Oh, that worked perfectly, thanks!

I thought that value was the number of rows being added, haha. Now I know!
 
Upvote 0
You are welcome.

To help avoid confusion, it can be written as
Code:
lRow = ws.Cells(Rows.Count, [COLOR=#ff0000]"H"[/COLOR]).End(xlUp).Offset(1, 0).Row
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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