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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Nevermind. Someone else helped me. The code works fine when I change the "Do While True" to "Do While lRow > 0"
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

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