Problem with UsedRange.Rows.Count

A

alainB

Hi,

I use this command to know what will be the next row to use to save th
data of the invoice I just printed. The data of every invoice is sav
on one line of the data sheet.

The problem is that if my DATA sheet is empty, no line used, th
command UsedRange.Rows.Count will return 1.

If one line is used, it will also return 1.

To go around this problem, I put a dummy in the first row. But I don'
like it.

Any idea on how to fix my problem ? Is there a way to hav
UsedRange.Rows.Count return 0 when no line are used?

Thanks!

Alai
 
M

Mike Fogleman

Add a line to check a cell to see if it is empty (""), If your UsedRange
count is 1. If it is empty, then count is 0.

X= ActiveSheet.UsedRange.Rows.Count
If X = 1 AND Range("A1").Value = "" Then X + 0

MIke F
 
M

Mike Fogleman

Sorry, I mis-typed, the last line should be

X= ActiveSheet.UsedRange.Rows.Count
If X = 1 AND Range("A1").Value = "" Then X = 0

MIke F

Mike Fogleman said:
Add a line to check a cell to see if it is empty (""), If your UsedRange
count is 1. If it is empty, then count is 0.

X= ActiveSheet.UsedRange.Rows.Count
If X = 1 AND Range("A1").Value = "" Then X + 0

MIke F
 
R

Ron de Bruin

Hi

Use this function in a module.

The UsedRange will not always give you the last row with Data
See Debra's site for this
http://www.contextures.com/xlfaqApp.html#Unused


Sub test()
MsgBox LRow(ActiveSheet) + 1
End Sub

Function LRow(sh As Worksheet)
On Error Resume Next
LRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
 
A

alainB

Thank you very much Ron!

I used your code and it is working fine.

I don't really understand it (the code)...but it is working!!

Thanks again!

Alai
 
Top