identifying last populated cell
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

replyReply Wed 8 Dec 2010, 16:58Delegate Lyndsey said...

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

For upcoming training course dates see: Pricing & availability

replyReply Wed 15 Dec 2010, 11:46Trainer Mark said...

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.

 

Please browse our web site to find out more about
excel classes and other Microsoft training courses.

Excel tip:

Using basic functions without doing formulas

When you highlight figures Autocalc tells you the total in the bottom right of the screen, but if you right click on the sum it will give you some basic functions. The functions are Min, Max, Average, Sum, Count, and Count Nums.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard