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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,575
Messages
6,125,624
Members
449,240
Latest member
lynnfromHGT

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