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

resolvedResolved · Medium Priority · Version 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:

Separate the year from a date

To separate the year from a date use the =year() function, eg a date is in cell A1 and in A2 you wish to display the year enter the function =year(A1)

View all Excel hints and tips


Server loaded in 0.08 secs.