Welcome to Windows Help!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Colouring any cell in worksheet with negative value

 
   Windows Help (Home) -> Microsoft Excel RSS
Next:  Automate Change of the format of a field to short..  
Author Message
Shivam.Shah

External


Since: Feb 16, 2010
Posts: 2



(Msg. 1) Posted: Tue Feb 16, 2010 1:59 pm
Post subject: Colouring any cell in worksheet with negative value
Archived from groups: microsoft>public>excel (more info?)

Hi all,

I have written the below code for making the cells from column to A to
BB fill with red colour, if they have a negative value in them.

I can't seem to make it work.....Any help will be appreciated! Thanks
very much!

Shivam

******************************
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const ColumnsToCheck As String = "A:BB"
If Not Intersect(Target, Range(ColumnsToCheck)) Is Nothing Then
If Target.Value < 0 Then
Target.Value.Select
Selection.Interior.ColorIndex = 3
End If
End If
End Sub

 >> Stay informed about: Colouring any cell in worksheet with negative value 
Back to top
Login to vote
Shivam.Shah

External


Since: Feb 16, 2010
Posts: 2



(Msg. 2) Posted: Tue Feb 16, 2010 3:31 pm
Post subject: Re: Colouring any cell in worksheet with negative value
Archived from groups: per prev. post (more info?)

Thanks again!!

On Feb 16, 5:16 pm, Dave Peterson wrote:
> First, if you're not using format|conditional formatting, then this would be a
> good use for it.  You'll find it much easier to implement, it won't destroy the
> undo/redo stack and it'll react to both user changes and formula recalculations.
>
> But if you want to use that worksheet_change event:
>
> Option Explicit
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
>     Const ColumnsToCheck As String = "A:BB"
>
>     If Target.Cells.Count > 1 Then
>         Exit Sub 'single cell at a time
>     End If
>
>     If Intersect(Target, Me.Range(ColumnsToCheck)) Is Nothing Then
>         'do nothing
>     Else
>         If Target.Value < 0 Then
>             Target.Interior.ColorIndex = 3
>         End If
>     End If
>
> End Sub
>
>
>
> "Shivam.Shah" wrote:
>
> > Hi all,
>
> > I have written the below code for making the cells from column to A to
> > BB fill with red colour, if they have a negative value in them.
>
> > I can't seem to make it work.....Any help will be appreciated! Thanks
> > very much!
>
> > Shivam
>
> > ******************************
> > Private Sub Worksheet_Change(ByVal Target As Excel.Range)
> >     Const ColumnsToCheck As String = "A:BB"
> >     If Not Intersect(Target, Range(ColumnsToCheck)) Is Nothing Then
> >        If Target.Value < 0 Then
> >         Target.Value.Select
> >         Selection.Interior.ColorIndex = 3
> >     End If
> >   End If
> >   End Sub
>
> --
>
> Dave Peterson

 >> Stay informed about: Colouring any cell in worksheet with negative value 
Back to top
Login to vote
Dave Peterson

External


Since: Oct 17, 2008
Posts: 38



(Msg. 3) Posted: Tue Feb 16, 2010 4:16 pm
Post subject: Re: Colouring any cell in worksheet with negative value
Archived from groups: per prev. post (more info?)

First, if you're not using format|conditional formatting, then this would be a
good use for it. You'll find it much easier to implement, it won't destroy the
undo/redo stack and it'll react to both user changes and formula recalculations.

But if you want to use that worksheet_change event:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const ColumnsToCheck As String = "A:BB"

If Target.Cells.Count > 1 Then
Exit Sub 'single cell at a time
End If

If Intersect(Target, Me.Range(ColumnsToCheck)) Is Nothing Then
'do nothing
Else
If Target.Value < 0 Then
Target.Interior.ColorIndex = 3
End If
End If

End Sub



"Shivam.Shah" wrote:
>
> Hi all,
>
> I have written the below code for making the cells from column to A to
> BB fill with red colour, if they have a negative value in them.
>
> I can't seem to make it work.....Any help will be appreciated! Thanks
> very much!
>
> Shivam
>
> ******************************
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
> Const ColumnsToCheck As String = "A:BB"
> If Not Intersect(Target, Range(ColumnsToCheck)) Is Nothing Then
> If Target.Value < 0 Then
> Target.Value.Select
> Selection.Interior.ColorIndex = 3
> End If
> End If
> End Sub
 >> Stay informed about: Colouring any cell in worksheet with negative value 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Turning negative to positive on a mass scale - I am currently working with data that I exported from Intuit Quicken to Excel. I was using a budget report that show all cash outflows as negative numbers. But I want to show these as positive numbers. I was wondering if there were some technique..

Change 3rd cell colour based on cell 1 >= cell2 in range - Hi all - I have looked through the group for a solution to this particular problem but i think my inexperience is possibly stopping me from seeing the solution .. so apologies if it has already been answered many times previously. My problem is this : ...

Email First Page of Worksheet Possible? - Hi, I was just wondering whether it's possible to email the first page of a worksheet comprised of multiple pages. Just the first page -summary report page. Is this possible?

Printing Cheque of Different sizes from the same Worksheet - Hi All, Kindly mention yours email ID for the sample file. >>>>>>>>>>>>>> Present Scenario >>>>>>>>>>>>>>>>>>>> I have bank account in 4 ...

Help Excel 2007 - worksheet scaling not working - Hoping that someone can help with this. I'm trying to print out a small worksheet on a '11x17' sheet. I've set the print area to the size I want and I have the scaling set to scale to '1 sheet wide x one sheet high' and the layout to 'landscape'. ..
   Windows Help (Home) -> Microsoft Excel All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]