Hi there,
Here are some examples which produce different results ...
Sub testme()
Dim LastRow As Long, LastCol As Long
LastRow = Cells.Find("*", after:=Cells(1, 1), searchorder:=xlByRows,
searchdirection:=xlPrevious).Row
LastCol = Cells.Find("*", after:=Cells(1, 1), searchorder:=xlByColumns,
searchdirection:=xlPrevious).Column
MsgBox "Row: " & LastRow & vbNewLine & "Col: " & LastCol
End Sub
Sub testme2()
Dim LastRow As Long, LastCol As Long
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
MsgBox "Row: " & LastRow & vbNewLine & "Col: " & LastCol
End Sub
You could probably shorten your code to ...
Public Sub SelectData()
With Workbooks(CurName).Sheets("Sheet1") 'assumed..
Set CopyArea = .Range("A1", "L" & .Cells(.Rows.Count,
1).End(xlUp).Row)
End With
CopyArea.Select
Get_Col_Widths 'not sure what this is..
End Sub
HTH
--
Regards,
Zack Barresse, aka firefytr
"loric" wrote in
message ...
I have the following code I am trying to edit:
Public Sub SelectData()
Workbooks(CurName).Activate
Range("A1").Activate
ActiveSheet.UsedRange.Select
rowscount = Selection.Rows.Count
Set CopyArea = Range("A1", ("L" & rowscount))
CopyArea.Select
Get_Col_Widths
End Sub
There are some hidden columns to the right of L that contain data. The
data goes all the way to row 149. In Excel if I look for the last row
it goes to 149, so does this code. For instance A:L might only have 45
rows. I want to just select those 45 rows and not the rows with hidden
data in them. Otherwise I get additional pages with no data in them.
Can this be done? I there a way in the Slection.Rows.Count to limit it
to look in just columns A-L?
--
loric
------------------------------------------------------------------------
loric's Profile:
http://www.excelforum.com/member.php...o&userid=33920
View this thread: http://www.excelforum.com/showthread...hreadid=536980