Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

identifying last populated cell

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Identifying the last populated cell and stopping the loop when i

Identifying the last populated cell and stopping the loop when i

ResolvedVersion 2003

Lyndsey has attended:
Excel VBA Intro Intermediate course

Identifying the last populated cell and stopping the loop when i

Hi

I have written the code below to do lots of look ups on some data. It all works fine but I can't seem to get the variable Data to work out the last populated cell. I know I need to use Range("A1").End(xlDown).Select but can't seem to get it right.

There are 2 sheets called Data and Look_Up and there is data in column A of each of them.

Please help
Thanks
Lyndsey

Sub LookUp()

Dim LookUp As String
Dim LookUpCount As Integer
Dim Cell As Range
Dim n As Integer
Dim Data As Range

LookUpCount = 2
LookUp = "A"

Do Until LookUp = ""

LookUp = Worksheets("Look_Up").Cells(LookUpCount, 1).Value
Set Data = Worksheets("Data").Range("A1:A7")


For Each Cell In Data

Cell.Activate
If Cell Like LookUp Then
If ActiveCell.Offset(0, 1).Value = Empty Then
ActiveCell.Offset(0, 1).Value _
= Worksheets("Look_Up").Cells(LookUpCount, 1).Offset(0, 1).Value
End If
End If

Next Cell

LookUpCount = LookUpCount + 1

Loop

End Sub

RE: Identifying the last populated cell and stopping the loop wh

Hello Lyndsey,

Hope you enjoyed your course with BEST Training.
Thank you for your question regarding last cell check.

You may want to use this code to find the last filled in cell,
range("a65000").end(xlup).row

or if you need the next available blank, +1 on the end of the line.

I hope this resolves your question. If it has, please mark this question as resolved.

If you require further assistance, please reply to this post. Or perhaps you have another Microsoft Office question?

Have a great day.
Regards,

Mark
Microsoft Office Specialist Trainer

Tue 21 Dec 2010: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Hide separate columns in Excel 2010

If you want to hide columns not adjacent to each other for example, Columns A, C and E then:-

1) Click on the fist column to be hidden i.e. A

2) Press and hold down the CTRL key

3) While holding the CTRL key, left click on the rest of the columns you want to hide i.e. C and E

4) Right click and choose Hide

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.