Last Row of Data in Column O

mrsushi

Board Regular
Joined
Nov 18, 2006
Messages
180
Office Version
  1. 2010
Good morning,

Can you help and advise how the range can be tweaked so the results in column is cleaned up ie make this more dynamic as the number of items in column O can change ?

Column O has 1446 rows, but the code products an output to row 1472. Is it possible to apply something like Lastrow= Range("O" & Rows.Count).End(xlUp).Row? if so, how can the below be amended to make this work?

Many thanks
M


Sub vba_check_workbook()

Dim myFolder As String
Dim myFileName As String
Dim myRange As Range
Dim myCell As Range

Application.ScreenUpdating = False

Set myRange = Range("O2:O1472")
myFolder = "S:\Other\invoices"

For Each myCell In myRange
myFileName = myCell.Value
If Dir(myFolder & "\" & myFileName) = "" Then
myCell.Offset(0, 1) = "File Doesn't Exists."
Else
myCell.Offset(0, 1) = "File Exists"
End If
Next myCell

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Like this?
VBA Code:
Sub vba_check_workbook()

Dim myFolder As String
Dim myFileName As String
Dim myRange As Range
Dim myCell As Range
Dim Lastrow As Long
Lastrow= Range("O" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False

Set myRange = Range("O2:O" & Lastrow)
myFolder = "S:\Other\invoices"

For Each myCell In myRange
myFileName = myCell.Value
If Dir(myFolder & "\" & myFileName) = "" Then
myCell.Offset(0, 1) = "File Doesn't Exists."
Else
myCell.Offset(0, 1) = "File Exists"
End If
Next myCell

Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
Like this?
VBA Code:
Sub vba_check_workbook()

Dim myFolder As String
Dim myFileName As String
Dim myRange As Range
Dim myCell As Range
Dim Lastrow As Long
Lastrow= Range("O" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False

Set myRange = Range("O2:O" & Lastrow)
myFolder = "S:\Other\invoices"

For Each myCell In myRange
myFileName = myCell.Value
If Dir(myFolder & "\" & myFileName) = "" Then
myCell.Offset(0, 1) = "File Doesn't Exists."
Else
myCell.Offset(0, 1) = "File Exists"
End If
Next myCell

Application.ScreenUpdating = True

End Sub

Perfect. Many thanks FlashBond.

Regards
M
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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