PDA

View Full Version : Find out row and column range



!pro
08-10-2017, 01:50 PM
Hi at all,

I got a lil problem.
Can somebody explain to me whats the differend between ..

AnZ = Cells(Rows.Count, 1).End(xlUp).Row ' shows a MsgBox with "3" cause Mappe1 : Hello (1,1) Hello (1,2) Hello(3,1)
and
Anz = UsedRange.Rows.Count ' aint work

By the way , why would this not work...
AnZ = Mappe1.Cells(Rows.Count, 1).End(xlUp).Row

' Mappe1 is declared Dim Mappe1 As Workbook
Set Mappe1 = ThisWorkbook

Im new in VBA , excuse my english im from Germany

mdmackillop
08-10-2017, 02:20 PM
'Mappe1 is I believe the VB code name for, in my terms, Sheet1. It can be used to refer to the sheet as shown below. You would not Dim Mappe1

To refer to it you could use
Dim ws as worksheet

Set ws = Mappe1
or
Set ws = Sheets("Mappe1")

If you qualify Cells with ws, Mappe1 or other, then Anz will return the value relevant to that sheet, rather than the Active Sheet.



Sub Test1()
'This will return Anz for the Active Sheet
Anz = Cells(Rows.Count, 1).End(xlUp).Row
MsgBox Anz
End Sub


Sub Test2()
'Mappe1 is I believe the VB code name for, in my terms, Sheet1
Anz = Mappe1.UsedRange.Rows.Count
MsgBox Anz
'or
Anz = Sheets("Mappe1").UsedRange.Rows.Count
MsgBox Anz
End Sub

!pro
08-21-2017, 10:41 AM
Hi thx for the Answer, Mappe1 is Workbook in my structure :)

mdmackillop
08-21-2017, 03:02 PM
Thanks for that. What are worksheets called?