Syntax for else elsif advice for £ character

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,830
Office Version
  1. 2007
Platform
  1. Windows
I have this code in use below.
Im having an issue with £ charcter where it just turns to yellow as its incorrect syntax i assume.

Can you advise please


VBA Code:
Dim Cell As Range
For Each Cell In Range("L:L")
  If Cell = "TO DO" Then
     Cell.Interior.Color = vbRed
    
  ElseIf Cell = "DONE" Then
     Cell.Interior.Color = vbBlue
    
  ElseIf Cell = ("£") Then
     Cell.Interior.Color = vbGreen
    
  End If
  Next Cell

Application.ScreenUpdating = True
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try the Character Function Chr(). Works for me

VBA Code:
Dim Cell As Range
For Each Cell In Range("A:A")
  If Cell = "TO DO" Then
     Cell.Interior.Color = vbRed
    
  ElseIf Cell = "DONE" Then
     Cell.Interior.Color = vbBlue
    
  ElseIf Cell = Chr(163) Then
     Cell.Interior.Color = vbGreen
    
  End If
  Next Cell
 
Upvote 0
@ipbr21054
I tested . it shows green as the condition is existed in the code.
and you should not use the whole column L , will take more much time until finshing . you don't need loop for the empty cells in column . I suggest set lastrow contains data .
 
Upvote 0
@ipbr21054
I tested . it shows green as the condition is existed in the code.
and you should not use the whole column L , will take more much time until finshing . you don't need loop for the empty cells in column . I suggest set lastrow contains data .
Can you advise the code you advise please
 
Upvote 0
Try the Character Function Chr(). Works for me

VBA Code:
Dim Cell As Range
For Each Cell In Range("A:A")
  If Cell = "TO DO" Then
     Cell.Interior.Color = vbRed
   
  ElseIf Cell = "DONE" Then
     Cell.Interior.Color = vbBlue
   
  ElseIf Cell = Chr(163) Then
     Cell.Interior.Color = vbGreen
   
  End If
  Next Cell
Ive noticed that £10 or any value aded to the £ is cancelled out.
Did i miss something as the intention was to use the £ followed by a number
 
Upvote 0
Can you advise the code you advise please
I don't understand !
just I use the same code in OP .
to getting help from the members I suggest for you upload file and explain well what's your problem.
 
Upvote 0
I don't understand !
just I use the same code in OP .
to getting help from the members I suggest for you upload file and explain well what's your problem.
You mentioned not Ito use the whole
Column so I’m asking for you to advise the line of code I should be using.
 
Upvote 0
I couldn’t get the code to work.
A user advised the correct syntax to use.

I have now used that code but I don’t see the cell changing Color.

If I enter the £ signed followed by a value example £100 the code doesn’t change cell colour.
 
Upvote 0
If I enter the £ signed followed by a value example £100 the code doesn’t change cell colour.
Hi,
untested but see if this update to your code will do what you want

VBA Code:
Sub ipbr21054()
    Dim Cell        As Range
    
    For Each Cell In Cells(1, "L").Resize(Cells(Rows.Count, "L").End(xlUp).Row)
    
        If Cell.Text = "TO DO" Then
            Cell.Interior.Color = vbRed
            
        ElseIf Cell.Text = "DONE" Then
            Cell.Interior.Color = vbBlue
            
        ElseIf Cell.Text Like "£*" Then
            Cell.Interior.Color = vbGreen
        Else
            Cell.Interior.Color = xlNone
        End If
        
    Next Cell
    
End Sub

You will note that I have also limited your search loop to scan just to the last row of data in Column L rather than the whole column.

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top