LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Copy To New Sheet

Hello again David,

I have just realized that I have not been receiving email notifications of
replies to my posts on this forum and have had to do a search on my recent
posts to find them. Hense the late reply. (I've now reported the problem to
Microsoft so hopefully they will fix it.)

However, a couple of observations in your code example.

You should reverse the two lines of code where you assign the active sheet
to a variable and Set the SearchRange. You can then use the worksheet
variable when assigning the range to SearchRange like the following.

Set sh = ActiveSheet
Set SearchRange = sh.Range("C1:Q" & LastRow)

The other thing is to take care when using the color constants to identify a
color. You cannot mix ColorIndex and Color constants as you have done.
ColorIndex and color constants are quite different in VBA. I think that your
line
Case 3, Not vbBlack
should actually be
Case 3, Not xlColorIndexAutomatic

The ColorIndex for black is 1 while the Color Constant vbBlack value is zero.

The ColorIndex values are 1 to 56
plus
xlColorIndexAutomatic with a value of -4105 (when color is set to automatic)
xlColorIndexNone with a value of -4142
See help for more on these. It is highly likely that what you are assuming
is black is actually xlColorIndexAutomatic.

Demonstration:
Set an ActiveCell to font color Automatic and run the following code and
observe the values returned. ColorIndex constants do not match the color
values (or Color constants). ColorIndex constant for Black is 1 while color
value for black is zero (same as vbBlack constant). vbBlack refers to a Color
Constant not ColorIndex.

Sub testFontColor()
'Type anything into the ActiveCell and
'set the font color to Automatic.

MsgBox "ActiveCell.Font.Colorindex is " & _
ActiveCell.Font.ColorIndex & vbCrLf & _
"ActiveCell.Font.Color is " & _
ActiveCell.Font.Color
End Sub

Further demo:
Insert the following code into a blank workbook and it will return all of
the colors for the ColorIndex constants in column A. The row number
represents the ColorIndex. Note that 1 is black.

Column B has the font Colors set to the 8 Color Constant colors with their
constant values and the adjacent column C has the names of the Color
Constant. Note that the values of Colors do not match the values of
ColorIndex.

Sub ColorDemo()
Dim i As Long
'Following sets the interior colors to ColorIndex
'The row number is the ColorIndex for the specified color
'NOTE: Used ColorIndex not color
For i = 1 To 56
Cells(i, 1).Interior.ColorIndex = i
Next i

'Following sets fonts to Color Constants
'with constant value in colored font and
'name of constant adjacent.
'NOTE: Used Color not ColorIndex
Cells(1, 2).Font.Color = vbBlack
Cells(1, 2).Value = vbBlack
Cells(1, 3).Value = "vbBlack"

Cells(2, 2).Font.Color = vbRed
Cells(2, 2).Value = vbRed
Cells(2, 3).Value = "vbRed"

Cells(3, 2).Font.Color = vbGreen
Cells(3, 2).Value = vbGreen
Cells(3, 3).Value = "vbGreen"

Cells(4, 2).Font.Color = vbYellow
Cells(4, 2).Value = vbYellow
Cells(4, 3).Value = "vbYellow"

Cells(5, 2).Font.Color = vbBlue
Cells(5, 2).Value = vbBlue
Cells(5, 3).Value = "vbBlue"

Cells(6, 2).Font.Color = vbMagenta
Cells(6, 2).Value = vbMagenta
Cells(6, 3).Value = "vbMagenta"

Cells(7, 2).Font.Color = vbCyan
Cells(7, 2).Value = vbCyan
Cells(7, 3).Value = "vbCyan"

'Following cell set to black interior otherwise
'white font is not visible.
Cells(8, 2).Interior.Color = vbBlack
Cells(8, 2).Font.Color = vbWhite
Cells(8, 2).Value = vbWhite
Cells(8, 3).Value = "vbWhite"

End Sub

--
Regards,

OssieMac


 
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
copy rows from one Data sheet to another sheet based on cell conte John McKeon Excel Discussion (Misc queries) 2 May 15th 10 06:49 AM
Auto copy cell data from source sheet to another wrkbook sheet IVLUTA Excel Programming 2 June 2nd 09 05:07 PM
Copy Paste from Class Sheet to Filtered List on Combined Sheet [email protected] Excel Programming 6 September 16th 08 04:30 PM
Help: auto-copy entire rows from 1 sheet (based on cell criteria) to another sheet. bertbarndoor Excel Programming 4 October 5th 07 04:00 PM
relative sheet references ala sheet(-1)!B11 so I can copy a sheet. RonMc5 Excel Discussion (Misc queries) 9 February 3rd 05 12:51 AM


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