Saved Searches Conditional HTML Formatting - netsuite

I'm trying to highlight/indicate individual fields within a saved search column based on a certain criteria. I don't want to highlight the specific row as that will highlight the entire row and not just the single column.
The rudimentary code I have now is
CASE WHEN {custbody487} = 'On Time'
THEN {custbody487}
ELSE CASE WHEN {custbody487} = 'On Hold'
THEN {custbody487}
ELSE CASE WHEN {custbody487} = 'Late'
THEN {custbody487}
END END END
How do I conditionally highlight only a specific column? I want to highlight On Time as green, On Hold as blue, etc. But I only want to highlight the text in that specific column.

You can add HTML formatting to saved searches.
Make sure you're using Formula(text) under results.
Here's what the above code looks like highlighted.
CASE WHEN {custbody487} = 'On Time'
THEN '<span style="color:green;font-weight:bold">' || {custbody487} || '</span>'
ELSE CASE WHEN {custbody487} = 'Late'
THEN '<span style="color:red;font-weight:bold">' || {custbody487} || '</span>'
ELSE CASE WHEN {custbody487} = 'On Hold'
THEN '<span style="color:blue;font-weight:bold">' || {custbody487} || '</span>'
END END END
Be advised that searches saved this way will not keep their HTML formatting upon export to PDF or CSV. It will be formatted as plain text.

Related

Userform textbox fills in if Vlookup finds the information related to the numbers inserted

I have an userform where people have to fill in with data. If the data already exists, when they put the information in the DocumentTitleBox, other textboxes should automatically fill in.
My code works with letters, but not with numbers.
For example, when I put "aaa", it returns the vlookup values. But if I put "123", it won't do anything, even though there is a vlookup for it.
I cannot figure it out why. This is part of my code:
Private Sub DocumentTitleBox_Change()
On Error Resume Next
Result = WorksheetFunction.VLookup(DocumentTitleBox.Value, Worksheets("example").Range("D:E"), 2, False)
FIND = WorksheetFunction.VLookup(DocumentTitleBox.Value, Worksheets("example").Range("D:E"), 1, False)
On Error GoTo 0
If FIND = DocumentTitleBox.Value Then
NameBox.Value = Result
End If
Thank you in advance!
I always use this kind of thing. Could be cleaned up and stuff but I like the flexibility and I change stuff all the time so this works for me.
Private Sub DocumentTitleBox_Change()
If IsNumeric(DocumentTitleBox.Value) Then
ReturnRow = Application.IfError(Application.Match(DocumentTitleBox.Value + 0, Worksheets("example").Columns(4), 0), "Not Found")
Find = Application.IfError(Application.Index(Worksheets("example").Columns(5), ReturnRow), "Not Present")
Else
ReturnRow = Application.IfError(Application.Match(DocumentTitleBox.Value, Worksheets("example").Columns(4), 0), "Not Found")
Find = Application.IfError(Application.Index(Worksheets("example").Columns(5), ReturnRow), "Not Present")
End If
If Not Find Like "Not Present" Then
NameBox.Value = Find
Else
NameBox.Value = ""
End If
End Sub
PS: I donĀ“t know how to avoid the match functions odd behaviour with strings/numbers so I just go with the +0 and IsNumeric trick. One thing to note is case sensitivity, adjust that as needed, right now its not.
If DocumentTitleBox is a text box, try using DocumentTitleBox.Text instead of DocumentTitleBox.Value.

Validate a TextBox before the _Change event is fired

I've got a form that has 3 TextBox controls on it: stock code, quantity, certificate number. The stock code TextBox is set to focus automatically when the form is loaded.
I've also attached a bar code scanner to my PC, as the user wants to be able to either scan a bar code to populate the TextBox, or manually type the data in.
The labels being scanned contain two bar codes. One is a certificate number and the other a stock code.
The stock bar code has a prefix of "SBC/", whilst a certificate bar code is prefixed with "C/".
When the user scans a bar code, if the TextBox in focus is the stock code TextBox, then I want to run a check as below.
Private Sub txtStockCode_Change()
On Error GoTo errError1
If Len(txtStockCode.Text) >= 5 Then
If bChangeCode Then
If Left(txtStockCode.Text, 2) = "C/" Then
msgbox "You have scanned the certificate barcode; please scan the stock barcode."
txtStockCode.Text = ""
Else
bChangeCode = False
txtStockCode.Text = Replace(txtStockCode.Text, "SBC/", "")
txtStockCode.Text = Replace(txtStockCode.Text, "*", "")
End If
End If
End If
Exit Sub
Let's say the focus is currently on the stock code TextBox.
If the stock bar code is scanned, the following should happen:
Stock code length is greater than 5
Left 5 characters do not = "C/", so correct code has been scanned
TextBox text value is updated to remove all * and the prefix of "SBC/"
E.g. "SBC/A12-TR0*" becomes "A12-TRO"
and
Certificate number length is greater than 5
Left 5 characters do = "C/", so incorrect code has been scanned
MsgBox to user
TextBox value is reset to ""
However, no matter which code is scanned into the stock code TextBox, the value is never validated.
E.g. "SBC/A12-TR0*" remains as "SBC/A12-TR0*" and "C/29760" remains as "C/29760"
As the validation code is the same in the certificate TextBox, the same pattern is repeated vice versa.
Why are my values not updating, or how can I validate the input before the _Change is fired?
EDIT
I've now changed my code to
Private Sub txtStockCode_Change
If txtStockCode.Text <> "" Then
txtStockCode.Text = Replace(txtStockCode.Text, "SBC/", "")
txtStockCode.Text = Replace(txtStockCode.Text, "*", "")
End If
End Sub
But it still displays the prefix of SBC/, yet is removing the two * characters (at the start and end of the barcode as is required for the scanner to read it as a barcode)
You could try to set the barcode reader to return Enter key at the end of the scanned barcode and then use the Keypress event to check it and make your changes.
Sub txtStockCode_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
If Len(txtStockCode.Text) >= 5 Then
If bChangeCode Then
If Left(txtStockCode.Text, 2) = "C/" Then
msgbox "You have scanned the certificate barcode; please scan the stock barcode."
txtStockCode.Text = ""
Else
bChangeCode = False
txtStockCode.Text = Replace(txtStockCode.Text, "SBC/", "")
txtStockCode.Text = Replace(txtStockCode.Text, "*", "")
End If
End If
End If
End If
End Sub

Check a range of text against a text string and return "yes" or "no"

I have a list of text strings (titles) and a list of "bad" keywords I want to identify within those titles.
The problem I've run into is how to identify individual text within the string. Several simple formulas can do this for an exact match, but I need it to identify words within the titles.
For example, in "Software sales representative" I need it to recognize "software" is on the list and return the word "bad".
I've browsed other questions on here and there's nothing that answers this specifically on Stacked.
The other similar questions have said this can be done with a asterisk/ wildcard, but this does not work. I know conditional formatting can do this, but I need a formula since I have over 100 "bad" keywords.
This is as far as I've gotten:
=IF(COUNTIF(K:K,"*"&E2&"*"),"Bad","Okay")
But this formula still only returns exact matches.
Column E is the titles. Column K is the keywords.
You will need to use this formula:
=IF(SUMPRODUCT(--(ISNUMBER(SEARCH($K$1:INDEX(K:K,MATCH("zzz",K:K)),E2)))),"Bad","Okay")
Put this Function in a module and call it from a cell like this =ContainsBadwords(badwordsrange,rangetotest;false;false)
Public Function ContainsBadwords(BadWordList As range, ByVal SuspectRange As range, Optional ExactMatch As Boolean = True, Optional CaseSensitive As Boolean = True)
For Each ArrayItem In SuspectRange
If Not CaseSensitive Then ArrayItem = Strings.lcase(ArrayItem)
For Each Subwhat In BadWordList
If ExactMatch Then
test = (ArrayItem = Subwhat)
Else
test = InStr(ArrayItem, Subwhat) >= 1
End If
If test Then: ContainsBadwords = test: Exit Function
Next Subwhat
If test Then: ContainsBadwords = test: Exit Function
n = n + 1
Next ArrayItem
End Function
Returns TRUE for blasphemy or FALSE if no bad words exist.

excel vba: check negative number in inputbox

I am using an inputbox the get a number from a user. I want to avoid not allowed input and am stuck with negative numbers. The only input which should be processed is an integer between 1 and 500. I don't understand why -1 is still triggered. Here is my code so far:
LBefore = InputBox("lines?", "", ">>> insert number <<<", 11660, 9540)
Select Case StrPtr(LBefore)
Case 0
'Cancel pressed
Exit Sub
Case Else
If (LBefore <> "") Then
'Check for numeretical value
If IsNumeric(LBefore) Then
cijfer = Abs(CByte(LBefore))
'Check to see if value is in allowed range
If (cijfer >= 1) And (cijfer <= 500) Then
'do stuff ...
end If
End If
End If
End Select
It's triggered because you use cijfer = Abs(CByte(LBefore)).
Abs is absolute function, so negative numbers become positive!
Try using cijfer = CInt(LBefore).

How to read the background color of a cell through a (ruby) script from Microsoft Excel on Mac Osx?

I want to get the background color of a cell of an Excel worksheet. I have already tried the following:
begin; require 'rubygems'; rescue LoadError; end
require 'appscript'
f = MacTypes::Alias.path(File.join(File.dirname(__FILE__), "planning.xls"))
excel = Appscript.app("Microsoft Excel")
excel.activate
excel.open f
w1 = excel.worksheets[1]
1.upto(10) do |i|
1.upto(10) do |j|
cell = w1.rows[i].cells[j]
print cell.value.get.to_s + " (#{cell.style_object.interior_object.pattern_color.get})"
end
puts ""
end
Unfortunately, I only get the cells value I can't seem to find the method that should give me the background color.
This is gives the value of the background color:
cell.interior_object.color.get

Resources