|
-
Jun 5th, 2006, 08:33 AM
#1
Thread Starter
Member
Conditional Formatting - multples from vba
Mornin all. ;0
I have a range of cells and a variety of conditions that I'm trying to create.
Specifically, if a number is below a range, do nothing, if it's within a range, I need to to change the font and color, and if it exceeds a range, I need it to change font and color yet again. (bold/orange and bold/red respectivly)
and I need to do this 22 times, once per row in range j6 27
I tried various combinations (wish I'd saved the code) but all I could get was an effect that turned everything black.
Can someone please help me with this?
-
Jun 5th, 2006, 08:55 AM
#2
Re: Conditional Formatting - multples from vba
Code:
rng.interior.colorindex=??
Record macros, experiment... thats the background
Code:
rng.font.colorindex = ?? 'guessing
I think this is the font colour - you can check with a recording macro.
If you want you should be able to set conditional formating for the ranges though.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jun 5th, 2006, 09:10 AM
#3
Thread Starter
Member
Re: Conditional Formatting - multples from vba
my fault for not clarifying, it's the code itself I need. I don't know how to code this in excel. I can record a macro but it acts like a drone, doing the same thing over and over again, regardless of the cell contents.
-
Jun 5th, 2006, 09:35 AM
#4
Re: Conditional Formatting - multples from vba
this will trigger on selection change....
put the code in "ThisWorkbook"
then change the numbers to what u want to test for
VB Code:
Dim WithEvents CWS As Worksheet
Private Sub CWS_SelectionChange(ByVal Target As Range)
For x = 10 To 16
For I = 6 To 27
If CWS.Cells(I, x) >= 10 And CWS.Cells(I, x) <= 25 Then
CWS.Cells(I, x).Interior.ColorIndex = 46
CWS.Cells(I, x).Font.Bold = True
ElseIf CWS.Cells(I, x) > 25 Then
CWS.Cells(I, x).Interior.ColorIndex = 3
CWS.Cells(I, x).Font.Bold = True
End If
Next
Next
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Set CWS = Sh
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 6th, 2006, 06:42 AM
#5
Re: Conditional Formatting - multples from vba
Alba:
sorry Yeah you need to use the code but reformat it to do what you want.
I usually do this by changing the selection object to proper objects and using a start position.
For example:
Create this code, create a toolbar button that runs the macro.
Click various cells and then the toolbar button.
Code:
Public Sub tellme()
Dim wrk As Workbook
Dim sht As Worksheet
Dim rng As Range
Set wrk = Application.Workbooks(1)
Set sht = wrk.Sheets(1)
Set rng = ActiveCell
MsgBox "The Address is " & rng.Address(False, False)
Set rng = Nothing
Set sht = Nothing
Set wrk = Nothing
End Sub
The rest is experimenting and getting used to Excels objects
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|