Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have data in 100 rows through 120 colunms. How can i get the index
100 and 120? I mean last valid data index. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Let's assume that your data is Activesheet.UsedRange:
Set r = ActiveSheet.UsedRange nLastRow = r.Rows.Count + r.Row - 1 MsgBox ("last row " & nLastRow) nLastColumn = r.Columns.Count + r.Column - 1 MsgBox ("last column " & nLastColumn) nFirstRow = r.Row MsgBox ("first row " & nFirstRow) nFirstColumn = r.Column MsgBox ("first column " & nFirstColumn) -- Gary''s Student - gsnu2007d " wrote: I have data in 100 rows through 120 colunms. How can i get the index 100 and 120? I mean last valid data index. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
you can return the adddress of the last used cell with this function
Function lastused() lastused = Cells.Find(What:="*", After:=[A1], _ SearchDirection:=xlPrevious).Address End Function You call it with =lastused() Mike " wrote: I have data in 100 rows through 120 colunms. How can i get the index 100 and 120? I mean last valid data index. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have data in 100 rows through 120 colunms. How can i get
the index 100 and 120? I mean last valid data index. Perhaps the subroutine listed after my signature is what you are after. You would use it like this. Declare four variables (for the top row, bottom row, left column and right column numbers). Here is a sample subroutine showing how to use it... Sub Test() Dim TopRow As Long Dim BottomRow As Long Dim LeftColumn As Long Dim RightColumn As Long ActualUsedRange TopRow, BottomRow, LeftColumn, RightColumn Debug.Print TopRow, BottomRow, LeftColumn, RightColumn End Sub Rick Sub ActualUsedRange(StartRow, EndRow, StartColumn, EndColumn) Dim X As Long If VarType(StartRow) 6 Or VarType(EndRow) 6 Or _ VarType(StartColumn) 6 Or VarType(EndColumn) 6 Then MsgBox "Numeric data types only!", vbCritical, "Data Type Error" Exit Sub End If With ActiveSheet.UsedRange StartRow = .Row + .Rows.Count - 1 StartColumn = .Column + .Columns.Count - 1 For X = .Row To .Row + .Rows.Count - 1 With ActiveSheet.Cells(X, Columns.Count) If EndColumn < .End(xlToLeft).Column Then EndColumn = .End(xlToLeft).Column End If End With With ActiveSheet.Cells(X, 1) If ActiveSheet.Cells(X, 1).Value < "" Then StartColumn = 1 ElseIf StartColumn .End(xlToRight).Column Then StartColumn = .End(xlToRight).Column End If End With Next For X = .Column To .Column + .Columns.Count - 1 With ActiveSheet.Cells(Rows.Count, X) If EndRow < .End(xlUp).Row Then EndRow = .End(xlUp).Row End If End With With ActiveSheet.Cells(1, X) If ActiveSheet.Cells(1, X).Value < "" Then StartRow = 1 ElseIf StartRow .End(xlDown).Row Then StartRow = .End(xlDown).Row End If End With Next End With End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Index/match - make blank cells return a blank value. | Excel Worksheet Functions | |||
Add if blank statement to index match | Excel Worksheet Functions | |||
how to delete a row index when row is blank | Excel Discussion (Misc queries) | |||
Start Cell B1 then find first blank cell, insert subtotal, next non blank, then next blank, sutotal cells in between......... | Excel Programming | |||
I want to index the first blank cell in a column of data | Excel Discussion (Misc queries) |