Run-Time Error when Trying to Populate Cells

midoop

New Member
Joined
Aug 9, 2013
Messages
37
Hello All,

I am trying to populate cells with a date that is located next to a cell with the word "Visit."

This is my code:

Code:
lRow = Cells(Rows.Count, "A").End(xlUp).Row

Do While True
[COLOR=#ff0000]If Cells(lRow, 6) = "Visit" Then
[/COLOR]    sLastValue = Cells(lRow, 5)
Else
    Cells(lRow, 5) = sLastValue
End If
lRow = lRow - 1
Loop

I get a run-time error 1004 (Application defined or object defined error) and when I hit "debug" the part in red font is the problem area.
The weird thing though is when I look at my spreadsheet, the code works. It does what I want. But this code is a small part of a larger macro, so the error causes my macro to stop running. Any and all help is much appreciated!<!-- BEGIN TEMPLATE: bbcode_code -->
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

midoop

New Member
Joined
Aug 9, 2013
Messages
37
Nevermind. Someone else helped me. The code works fine when I change the "Do While True" to "Do While lRow > 0"
 

Watch MrExcel Video

Forum statistics

Threads
1,133,424
Messages
5,658,718
Members
418,466
Latest member
lisamck

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
Top