Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Format sheets w/varying ranges

I need to format 5 sheets the same way; number formats, borders, etc. The
number of rows to format on each sheet is different. I'd like to loop through
the formatting code but specify the range to format on each sheet. Starting
row on each sheet is 9, but I need to determine the last cell and select the
range to format. I'm trying to avoid repeating code. If you can help I'd
really appreciate it. TIA, and have a great holiday!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Format sheets w/varying ranges

If you want to find the last cell in the used range, check out this
code. It assumes that A9 is the upper-left cell of your range.

Dim myLastRow As Long
Dim myLastColumn As Long
Dim myLastCell As String
Dim myRange As String

myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
myLastColumn = Cells.Find("*", [A1], , , xlByColumns,
xlPrevious).Column
myLastCell = Cells(myLastRow, myLastColumn).Address
myRange = "A9:" & myLastCell

"myRange" will be the block of text consisting of whatever range is on
the sheet.

You can use this variable with any of the properties of the Range
object, such as: Cut, Copy, Sort, Clear, etc

ex:
Range(myRange).Cut


HTH,
JP

On Dec 20, 2:32 pm, cottage6
wrote:
I need to format 5 sheets the same way; number formats, borders, etc. The
number of rows to format on each sheet is different. I'd like to loop through
the formatting code but specify the range to format on each sheet. Starting
row on each sheet is 9, but I need to determine the last cell and select the
range to format. I'm trying to avoid repeating code. If you can help I'd
really appreciate it. TIA, and have a great holiday!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Format sheets w/varying ranges

Awesome, JP! Thanks for the help. I'll be using this code in many workbooks
I'm sure.

"JP" wrote:

If you want to find the last cell in the used range, check out this
code. It assumes that A9 is the upper-left cell of your range.

Dim myLastRow As Long
Dim myLastColumn As Long
Dim myLastCell As String
Dim myRange As String

myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
myLastColumn = Cells.Find("*", [A1], , , xlByColumns,
xlPrevious).Column
myLastCell = Cells(myLastRow, myLastColumn).Address
myRange = "A9:" & myLastCell

"myRange" will be the block of text consisting of whatever range is on
the sheet.

You can use this variable with any of the properties of the Range
object, such as: Cut, Copy, Sort, Clear, etc

ex:
Range(myRange).Cut


HTH,
JP

On Dec 20, 2:32 pm, cottage6
wrote:
I need to format 5 sheets the same way; number formats, borders, etc. The
number of rows to format on each sheet is different. I'd like to loop through
the formatting code but specify the range to format on each sheet. Starting
row on each sheet is 9, but I need to determine the last cell and select the
range to format. I'm trying to avoid repeating code. If you can help I'd
really appreciate it. TIA, and have a great holiday!



Reply
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
Creating a chart with varying data value ranges Anthony Blackburn Excel Discussion (Misc queries) 1 May 17th 10 05:41 PM
sumproduct with varying column ranges rami Excel Worksheet Functions 1 November 20th 08 12:43 AM
Calculation for varying ranges kjh198 Excel Worksheet Functions 3 June 5th 08 10:06 PM
Copy cells with varying ranges (VBA) BCLivell Excel Programming 0 June 6th 07 07:30 PM
making a formula over varying ranges Hein[_4_] Excel Programming 4 October 11th 05 01:19 PM


All times are GMT +1. The time now is 10:26 PM.

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

About Us

"It's about Microsoft Excel"