conditional formatting with WILDCARD

MR3

Board Regular
Joined
Jun 10, 2008
Messages
175
is it possible to format a row with the condition NAME_* where name is always the same prefix?
thus if a row contains this particular prefix it will flood fill the entire cell
 
Last edited:
i didn't realize you posted.. but this is what i came up with and its not working properly.

Sub ApplyCF()
Dim var1 As Integer
Dim var2 As String
var2 = InputBox("Enter a String", "Input")
var1 = Len(var2)
With Columns("C")
.Select '2007 & earlier
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=LEFT(C1,var1)=""var2"""
.FormatConditions(1).Interior.ColorIndex = 35
MsgBox "Value added to total."

End With
End Sub

I am going to try your code now Peter, thanks for posting.
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
i didn't realize you posted.. but this is what i came up with and its not working properly.
NO, you haven't built up the formula string correctly. You could do it like this
Code:
.FormatConditions.Add Type:=xlExpression, _
    Formula1:="=LEFT(C1," & var1 & ")=""" & var2 & """"
Note though that if you do not put a check in about var1 being greater than 0, your whole column will be coloured if the user does any of these things with the Input Box :
- Closes it with the X at the top right, or
- Clicks OK without entering anything in the text box, or
- Clicks Cancel

Also note that when posting code, please have your code indented and keep that indentation by using code tags as I have done here, or use the VBHTML Maker as I did with my earlier code. It is much harder to read and debug unindented code and many potential helpers will jsut by-pass your thread if your code is not indented. Further info in my signature block.
 
Upvote 0
NO, you haven't built up the formula string correctly. You could do it like this
Code:
.FormatConditions.Add Type:=xlExpression, _
    Formula1:="=LEFT(C1," & var1 & ")=""" & var2 & """"
Note though that if you do not put a check in about var1 being greater than 0, your whole column will be coloured if the user does any of these things with the Input Box :
- Closes it with the X at the top right, or
- Clicks OK without entering anything in the text box, or
- Clicks Cancel

Also note that when posting code, please have your code indented and keep that indentation by using code tags as I have done here, or use the VBHTML Maker as I did with my earlier code. It is much harder to read and debug unindented code and many potential helpers will jsut by-pass your thread if your code is not indented. Further info in my signature block.

sorry about not posting the VBHTML. i will be sure to post code correctly from now on.

on my input window is there a way to input 2 different values in the same box or do i have to declare another MSG box?
 
Upvote 0
on my input window is there a way to input 2 different values in the same box or do i have to declare another MSG box?
I'm not sure what you want to with the two inputs but for collecting them, a few choices come to mind:

1. Create a Userform with two Text Boxes to collect the information.

2. Have an Input Box collect the first value then another Input Box to collect the second value.

3. Use a single Input Box and enter the two values separated by some special character (eg "/")
 
Upvote 0
These are really great options Peter.

How about the User Input Box, where they can enter data and use a check box in that same box to choose what other data is to be.

So keeping it similar but just adding a choice AM or PM and then there is a check box next to that which refers to a specific column.
 
Upvote 0
How about the User Input Box, where they can enter data and use a check box in that same box ...
An Input Box as we used in the earler code in this thread is a simple structure that allows a single input. If you want anything more complecated than that, you will need to use a UserForm. UserForms are not a real strength of mine, but here is one place that has some resources you might find helpful.
http://www.contextures.com/xlUserForm01.html
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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