Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Set formatting variable

Hi All,

Can I set Range A1:H2 with Formatting:
interior color =Black, font =White?

....
But if Usedrange.column H then Set Formatting
on Range:A1:Usedrange.column2

if usedrange.column<H then keep range A1:H2

Brgds Sige

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Set formatting variable

Hi Sige,

The following does, I think, what you ask. However, this may well not be
what you intend.

Perhaps, therefore, it might be worthwhile explaining what it is that you
are trying to achieve and, possibly, why.

My code may well be susceptible to significant simplification, but my
incertitude as to your aims precludes me from investigation,

'=============
Public Sub Tester()
Dim rng1 As Range
Dim rng2 As Range
Dim LastCol As Long
Dim lastRow As Long

Set rng1 = ActiveSheet.UsedRange
With rng1
LastCol = .Columns(.Columns.Count).Column

lastRow = .Rows.Count - .Row + 1
End With

If LastCol 8 Then
Set rng2 = Range("A1", _
Cells(lastRow, rng1.Columns(2).Column))
Else
Set rng2 = Range("A1:H2")
End If
With rng2
.Interior.ColorIndex = 1
.Font.ColorIndex = 2
End With
End Sub
'<<=============

---
Regards,
Norman



"Sige" wrote in message
oups.com...
Hi All,

Can I set Range A1:H2 with Formatting:
interior color =Black, font =White?

...
But if Usedrange.column H then Set Formatting
on Range:A1:Usedrange.column2

if usedrange.column<H then keep range A1:H2

Brgds Sige



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Set formatting variable

Hi Norman,

The black cells I am coloring should indicate how wide (wide) the last
column is going of my UsedRange ... always coloring row 1 & 2.(titles
will be written in here)

I think the code should be as follows:

If LastCol 8 Then
Set rng2 = Range("A1", Cells(2, LastCol))

The thing is that the UsedRange can change while working on the sheet
.... Worksheet_SelectionChange might be a solution to update this
behaviour...& Also ressetting the UsedRange.
I am afraid though that this will invoke emptying the Undo-list!

Way around?
Brgds Sige

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Set formatting variable

Hi Sige,

I think the code should be as follows:

If LastCol 8 Then
Set rng2 = Range("A1", Cells(2, LastCol))

The thing is that the UsedRange can change while working on the sheet
... Worksheet_SelectionChange might be a solution to update this
behaviour...& Also ressetting the UsedRange.
I am afraid though that this will invoke emptying the Undo-list!



If your purpose is to set the black background / white font for rows 1:2,
why bother to monitor the number of columns in the used range?

In the absence of definitive information, make an informed guess:

With Range("A1:Z2")
.Interior.ColorIndex = 1
.Font.ColorIndex = 2
End With

---
Regards,
Norman



"Sige" wrote in message
ups.com...
Hi Norman,

The black cells I am coloring should indicate how wide (wide) the last
column is going of my UsedRange ... always coloring row 1 & 2.(titles
will be written in here)

I think the code should be as follows:

If LastCol 8 Then
Set rng2 = Range("A1", Cells(2, LastCol))

The thing is that the UsedRange can change while working on the sheet
... Worksheet_SelectionChange might be a solution to update this
behaviour...& Also ressetting the UsedRange.
I am afraid though that this will invoke emptying the Undo-list!

Way around?
Brgds Sige



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Set formatting variable

Hi Norman,

Hmmm... resetting last cell (column) ... once columns are colored they
will be part of the used range. So can only expand to right it
seems...

Unless the usedrange gets evaluated not taking into account row 1&2.

It will serve its purpose like this I guess.

Sige



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
Formatting a two-variable data table via sarpi Excel Worksheet Functions 0 June 16th 11 04:05 PM
Conditional Formatting using variable text murkaboris Excel Discussion (Misc queries) 4 August 31st 09 03:07 AM
Stuffing Numeric Variable Values into Footnote with formatting Dkline[_3_] Excel Programming 2 August 15th 05 09:44 PM
Formatting a Variable Arturo Excel Programming 1 October 18th 04 10:38 PM
How to copy formatting when moving from cell to variable to another cell on another worksheet kls[_2_] Excel Programming 1 September 11th 04 10:42 PM


All times are GMT +1. The time now is 12:19 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"