Iam using this code for replace a word with the same word with strike. Its works fine.
replace Str[1] with "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & Str[1] & "</font></strike>" in myHtml
But when i replace it vice versa its not working. Iam using this code fore replacing
replace "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & Str[1] & "</font></strike>" with Str[1] in myHtml
Your code actually works for me. it strikes and colours the "def" on the first answerbut it is back to normal on the second. Maybe you have some issue with escaping the quotes?
put "abc def" into myHtml
put "def" into Str[1]
replace Str[1] with "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & Str[1] & "</font></strike>" in myHtml
answer myHtml -- "def" is yellow and stroke
replace "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & Str[1] & "</font></strike>" with Str[1] in myHtml
answer myHtml -- "def" is back to normal text
Working example with two Buttons and one text field:
Button 1:
on mouseUp
put the htmlText of field "MytextField" into myHtml
put item 1 of myhtml into str[1]
replace Str[1] with "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & Str[1] & "</font></strike>" in myHtml
set the htmlText of fld "MytextField" to myHtml
end mouseUp
Button 2:
on mouseUp
put the htmlText of field "MytextField" into myHtml
put "abc" into str[1]
replace "<strike><font bgcolor=" & quote & "#FFFF00" & quote & ">" & Str[1] & "</font></strike>" with Str[1] in myHtml
set the htmlText of fld "MytextField" to myHtml
end mouseUp
and how I set my textfield
set the htmltext of field "mytextfield" to "abc,def"
Related
It seems to be a problem with some characters in it
My original formula in the worksheet (working):
ThisWorkbook.Worksheets("Zazmluvnenia").Cells("3", "AM").Value = "=Výkony!M4 & ", " & TEXT(Výkony!J4;"d.m.yyyy") & ", " & TEXT(Výkony!K4;"hh:mm")"
Putting this into VBA doesn't work because of the quotes. I tried to solve the problem this way: How do I put double quotes in a string in vba?
I changed my code according to the answers on the question above:
"=Výkony!M3 & " & Chr(34) & ", " & Chr(34) & " & TEXT(Výkony!J3;" & Chr(34) & "d.m.yyyy" & Chr(34) & ") & " & Chr(34) & ", " & Chr(34) & " & TEXT(Výkony!K3;" & Chr(34) & "hh:mm" & Chr(34) & ")"
And error '1004' occurred.
Double Quotes vs CHR(34)
Your CHR solution was almost fine, but you didn't know that VBA doesn't recognize the semi-colon (;) as a separator like Excel does. You always have to replace every semi-colon (used as a separator) with a comma in VBA.
Similarly VBA uses the dot (.) as the decimal separator.
The Code
Option Explicit
Sub SEMI()
Dim strF As String
' Double double-quotes ("") in several rows.
strF = "=Výkony!M4&"", """ _
& "&TEXT(Výkony!J4,""d.m.yyyy"")&"", """ _
& "&TEXT(Výkony!K4,""hh:mm"")"
' CHR(34) in several rows.
strF = "=Výkony!M4&" & Chr(34) & ", " & Chr(34) _
& "&TEXT(Výkony!J4," & Chr(34) & "d.m.yyyy" & Chr(34) & ")&" _
& Chr(34) & ", " & Chr(34) _
& "&TEXT(Výkony!K4," & Chr(34) & "hh:mm" & Chr(34) & ")"
' Double double-quotes ("") in one row.
strF = "=Výkony!M4&"", ""&TEXT(Výkony!J4,""d.m.yyyy"")&"", ""&TEXT(Výkony!K4,""hh:mm"")"
' CHR(34) in one row.
strF = "=Výkony!M4&" & Chr(34) & ", " & Chr(34) & "&TEXT(Výkony!J4," & Chr(34) & "d.m.yyyy" & Chr(34) & ")&" & Chr(34) & ", " & Chr(34) & "&TEXT(Výkony!K4," & Chr(34) & "hh:mm" & Chr(34) & ")"
ThisWorkbook.Worksheets("Zazmluvnenia").Cells("3", "AM").Value = strF
End Sub
I am performing a web query and want to filter a column by a cell reference.
ThisWeek = ThisWorkbook.Sheets("Summary").Range("A1").Value
LastWeek = ThisWorkbook.Sheets("Summary").Range("M1").Value
ActiveWorkbook.Queries.Add Name:="1245", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source =
Json.Document(Web.Contents(""" & finalstr & """))," & Chr(13) & "" &
Chr(10) & " each ([Column1.report_begin_date] = " < " & ThisWeek & " > "
or [Column1.report_begin_date] = " < " & Last Week & " > ")"
#""Filtered Rows"""
ThisWeek and LastWeek are both strings that change each day and I want the query to filter out by these dates. VBA doesn't recognize the way Im formatting my variable names and doesn't recognize them as an editable variable.
Basically what you want to do is add quotation marks for your date string variable, correct?
You can achieve that by using: """" (4 times quotation marks)
Which will create a simple "
So if you add it to both sides of your string variable, you will get what you need, as follows:
[...] " < " & """" & ThisWeek & """" & [...]
Hope this helps
I'm reading a value from a cell, the contents has the & as part of the string. For example the cell value is "BAU Dev & Production Support-Partner"
xCellValue = xRg.Cells(i, 2).Value
xMsg = " This is a test of the concatenation "
xMsg = xMsg & xCellValue & vbCrLf & vbCrLf
When I print xCellValue it shows "This is a test of the concatenation BAU Dev".
Hence the & inside the cell has become part of the concatenation. How do I tell VBA not to interpret the & inside the cell?
Thanks to all those who responded. I've Debug.Print and further identified the issue:
xURL = "mailto:" & xEmail & "?subject=" & xSubj & "&body=" & xMsg
Debug.Print xURL
ShellExecute 0, vbNullString, xURL, vbNullString, vbNullString, vbNormalFocus
Up to the Debug.Print xURL, the & is still showing in the string. However, the string terminates after the & in the ShellExecute xMsg. The problem is not in reading the cell value as I had previous thought. If I set
xMsg = " This is a test & of the concatenation "
the body message in the ShellExecute will only show " This is a test"
Ok, I found the solution. I needed
' Replace & with %26 (hex)
xMsg = Application.WorksheetFunction.Substitute(xMsg, "&", "%26")
It was the same reason I needed
' Replace spaces with %20 (hex)
xSubj = Application.WorksheetFunction.Substitute(xSubj, " ", "%20")
xMsg = Application.WorksheetFunction.Substitute(xMsg, " ", "%20")
' Replace carriage returns with %0D%0A (hex)
xMsg = Application.WorksheetFunction.Substitute(xMsg, vbCrLf, "%0D%0A")
For more details, check URL encoding
I'm trying to create a vba code to write a formula in determined cell on my sheet, but it doesn't work. What's wrong ? 'Cause, i really don't see what am i doing wrong in this code.
Range("BC" & ActiveCell.Row).Formula = "=IF($BB" & ActiveCell.Row & "=" & """" & "REVIEW" & """" & ";IF(ROW($BB" & ActiveCell.Row & ")<MAX(IF($BB:$BB=" & """" & "OK" & """" & ";$A:$A));IF(TODAY()-$AY" & ActiveCell.Row & ">=3;" & """" & "DROP" & """" & ";" & """" & "REVIEW" & """" & ");" & """" & "REVIEW" & """" & ");" & """" & """" & ")"
Your computer's use of a ; as the regional list separator is fouling you up. VBA is very EN-US-centric so the Range.Formula and Range.FormulaR1C1 expect a comma (,) as the function's argument list separator.
Range("BC" & ActiveCell.Row).Formula = "=IF($BB" & ActiveCell.Row & "=" & """" & "REVIEW" & """" & ", IF(ROW($BB" & ActiveCell.Row & ")<MAX(IF($BB:$BB=" & """" & "OK" & """" & ", $A:$A)), IF(TODAY()-$AY" & ActiveCell.Row & ">=3, " & """" & "DROP" & """" & ", " & """" & "REVIEW" & """" & "), " & """" & "REVIEW" & """" & "), " & """" & """" & ")"
Alternately, Range.FormulaLocal property or Range.FormulaR1C1Local property can be used with your own semi-colon as the list separator.
Range("BC" & ActiveCell.Row).FormulaLocal = "=IF($BB" & ActiveCell.Row & "=" & """" & "REVIEW" & """" & ";IF(ROW($BB" & ActiveCell.Row & ")<MAX(IF($BB:$BB=" & """" & "OK" & """" & ";$A:$A));IF(TODAY()-$AY" & ActiveCell.Row & ">=3;" & """" & "DROP" & """" & ";" & """" & "REVIEW" & """" & ");" & """" & "REVIEW" & """" & ");" & """" & """" & ")"
Your doubling up double quotes within a quoted string is a bit verbose and xlR1C1 notation would save some steps. TEXT(,) is the same as "" in a formula; each produces the same zero-length string.
Range("BC" & ActiveCell.Row).Formula = "=IF($BB" & ActiveCell.Row & "=""REVIEW"", IF(ROW($BB" & ActiveCell.Row & ")<MAX(IF($BB:$BB=""OK"", $A:$A)), IF(TODAY()-$AY" & ActiveCell.Row & ">=3, ""DROP"", ""REVIEW""), ""REVIEW""), TEXT(,))"
'.FormulaR1C1
Range("BC" & ActiveCell.Row).FormulaR1C1 = "=IF(RC54=""REVIEW"", IF(ROW(R:R)<MAX(IF(C54:C54=""OK"", C1:C1)), IF(TODAY()-RC51>=3, ""DROP"", ""REVIEW""), ""REVIEW""), TEXT(,))"
The xlA1 and xlR1C1 formula rewrites above each produce the following when ActiveCell is on the second row.
=IF($BB2="REVIEW", IF(ROW($BB2)<MAX(IF($BB:$BB="OK", $A:$A)), IF(TODAY()-$AY2>=3, "DROP", "REVIEW"), "REVIEW"), TEXT(,))
As I mentioned in comments above, that formula would seem to be an array formula. In that case, use the .Formula comma based rewrite but change the Range.Formula property to Range.FormulaArray.
I am trying to pass multiple variables to a .OnAction call for a button. I have not been able to find answers that relate to multiple variables, and I can do it with just one variable. Here is what I have that works for one variable:
shpBar.OnAction = "'Button_Click """ & strText & """'"
How can I add two other variables to this (such as VarA and VarB)?
Assuming that VarA and VarB are variants or numeric variables, this would work:
.OnAction = "'Button_Click """ & strText & """," & varA & "," & varB & " '"
If they are strings, you need to add two more double-quotes around each variable name.
.OnAction = "'Button_Click """ & strText & """,""" & varA & """,""" & varB & """ '"