LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2
Default how to find used region with macro

Hi,

sorry if this obvious or has been asked recently.

I have a macro that goes through all rows and all columns in a
selection. If a row or a column is hidden, the font of that row or
column is changed.

A friend wants to use the macro in a Workbook with many sheets. He
asked if I could change it so that he does not need to do a selection
on every sheet before he runs it.

I imagine that a nested loop through all rows and all columns will
take a long time?

I´ve tried to figure out how to get the range defined by the last row
and the last column filled with data.

First I tried with CurrentRegion but then I tried End(xlUP) but the
code I´ve come up with is not reliable. I get strange results.

I would be most thankful for any hint.

BR,
Oerjan Skogloesa
=============

Sub Makro1()
Dim Sh As Worksheet
Dim myColumn As Range
Dim myRange As Range
Dim A, B, C, D, HiRow, HiCol

For Each Sh In ActiveWorkbook.Worksheets

A = Sh.Rows.Count
HiRow = 1

For Each myColumn In Sh.Columns

B = myColumn.Column
C = (Cells(A, B).Address())

D = Range(C).End(xlUp).Row

If D HiRow Then HiRow = D

If D 1 Then HiCol = B

Next myColumn

'this is just for seeing the result
With Sh
..Activate
..Range(.Cells(1, 1), .Cells(HiRow, HiCol)).Select
End With

MsgBox (HiRow & " " & HiCol)

Next Sh

End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Additional raws only in some region antares Excel Discussion (Misc queries) 10 November 30th 08 01:23 AM
Counting a Region Paul D Byrne. Excel Worksheet Functions 2 November 27th 08 03:01 AM
VBA determine computer region Viperv10 Setting up and Configuration of Excel 5 May 27th 07 01:39 AM
Region Zaahir Excel Discussion (Misc queries) 2 November 14th 06 02:22 PM
Is it possible to count if within a number region? themax16 Excel Discussion (Misc queries) 3 May 22nd 05 06:46 PM


All times are GMT +1. The time now is 04:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"