I have a bunch of formulas all over different rows and columns in my Excel sheet. Some of the formulas are of the form: =($B$12-G12)*$B$3*G3
All I want to do is replace the ")" with ")^2". I tried using the Ctrl + F -> Replace section to look in Formulas but for some reason Excel says cannot find a match...All the cells I am trying to replace are of the form:
=(Cell1-Cell2)*Cell 3*Cell4
I just want to replace that )* by ^2*
What can I do?
This is what I have tried searching:
Make sure the Look in option is set to Formulas:
EDIT#1:
As per your comment, you must use tilda in the Find string:
Find and search using:
)~*
What I was having difficulty with was the * and I found the solution is to just use a ~ and it will fix the problem.
In summary of the article I left as a comment (http://www.mrexcel.com/archive/General/29013.html), you need to use ~ [the character to the left of the 1 on a standard English QWERTY keyboard] before *, in order to specifically tell excel that you want to look for an asterisk, not use the asterisk as a wildcard.
Related
Here is an example of what I want. Suppose a text:
paper[1], some texts[2], paper[3]
Here is the expected result ==>
paper[1], some texts[2], paper[3]
That is, I want to replace all "paper[1]" with "paper[1]" and similarly, replace "paper[3]" with "paper[3]" but keep the texts[2] unchanged.
I have noticed that word can not search the mixing format text, e.g., I can not find the text "paper[3]". So I may need the VBA to achieve this. Any ideas? Thanks!
You don't even need VBA for that! A wildcard Find/Replace can be used, where:
Find = paper\[[13]\]
Replace = ^&
and the replacement font is set to 'not superscript'. If you really want a macro, record the above.
I'm searching for "***" in the A column, I need to know how many times it appears so that I can loop my code that many times. I can't seem to find out how to do it. Thanks for the help!
If your cells just have "***" in them and it's not anything else, you can invoke the worksheet function CountIF
Application.WorksheetFunction.CountIf(ActiveSheet.Range("A:A"), "~*"&"~*"&"~*")
Edited per TMH8885's comment and the asterisk being a wildcard. The tilde does seem to work.
How about this function within excel: https://support.microsoft.com/en-us/kb/214153
It shows the function: =COUNTIF(range,"text") which you can use as =COUNTIF(A:A,"***")
UPDATE Actually need to escape wildcards so it would be: =COUNTIF(A:A,"~*~*~*")
It counts the number of matched to your pattern "***" in column A.
this is new for me. I have an issue trying to run a formula in VBA using IF.
The idea is to include in AR3 column a modification date when in C3 there contains information.
This is what I wrote:
Range("AR3").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-3]="";"";IF(RC[-44]="";NOW();RC[-44])"
Thanks in advance!!
A couple of things are not right with your formula:
You need to escape the double quotes (with double quotes... so four in total)
You are missing a closing parenthesis
This is optional, but you don't need to select the range
You can use the following corrected statement:
Range("AR3").FormulaR1C1 = "=IF(RC[-3]="""","""",IF(RC[-44]="""",NOW(),RC[-44]))"
Next time you run into this kind of trouble, just use the macro recorder: click on "Record macro", and enter your formula. Plus, you can always change the display in Excel to the R1C1 Reference style (Options > Formulas > R1C1 reference style) when that is helpful (Personally I've mapped this change to a shortcut key combination so I can easily get column numbers if needed)
I have a formula:
=IF(OR(AND(H6<>"";I6<>"");AND(H6="";I6=""));"Price error";IF(H6<>"";F6*H6;IF(G6<>"";G6*I6;"")))
I can use VBA to write
Range("J6") = "=IF(OR(AND(H6<>"""";I6<>"""");AND(H6="""";I6=""""));""Price error"";IF(H6<>"""";F6*H6;IF(G6<>"""";G6*I6;"""")))"
But what is the best approach if I want to:
enter the formula into many rows of column J?
make sure that the formula works regardless of language settings? For example I know that IF is called OM in the Swedish version of Excel
enter the formula into many rows of column J?
you could apply formula for entire range as follows:
Range("J6:J100").Formula = "=IF(H6=...)"
in that case formula would be automatically adjusted:
in J6 you'd have =IF(H6=...)
in J7 you'd have =IF(H7=...)
....
in J100 you'd have =IF(H100=...)
make sure that the formula works regardless of language settings? For
example I know that IF is called OM in the Swedish version of Excel
use Range.Formula instead Range.FormulaLocal and. In that case you should apply formula using "English" version (e.g. If instead Om in the Swedish) and always use comma , instead semicolon ; as formula delimeter (even if your regional separator is semicolon ;):
Range("J6:J100").Formula = _
"=IF(OR(AND(H6<>"""",I6<>""""),AND(H6="""",I6="""")),""Price error"",IF(H6<>"""",F6*H6,IF(G6<>"""",G6*I6,"""")))"
I'm trying to use VBA to write a formula into a cell in Excel.
My problem is that when I use a semicolon (;) in my formula, I get an error:
Run-time error 1004
My macro is the following :
Sub Jours_ouvres()
Dim Feuille_Document As String
Feuille_Document = "DOCUMENT"
Application.Worksheets(Feuille_Document).Range("F2").Formula = "=SUM(D2;E2)"
End Sub
You can try using FormulaLocal property instead of Formula. Then the semicolon should work.
The correct character to use in this case is a full colon (:), not a semicolon (;).
The correct character (comma or colon) depends on the purpose.
Comma (,) will sum only the two cells in question.
Colon (:) will sum all the cells within the range with corners defined by those two cells.
Treb, Matthieu's problem was caused by using Excel in a non-English language. In many language versions ";" is the correct separator. Even functions are translated (SUM can be SOMMA, SUMME or whatever depending on what language you work in). Excel will generally understand these differences and if a French-created workbook is opened by a Brazilian they will normally not have any problem.
But VBA speaks only US English so for those of us working in one (or more) foreign langauges, this can be a headache.
You and CharlesB both gave answers that would have been OK for a US user but Mikko understod the REAL problem and gave the correct answer (which was also the correct one for me too - I'm a Brit working in Italy for a German-speaking company).
I don't know why, but if you use
(...)Formula = "=SUM(D2,E2)"
(',' instead of ';'), it works.
If you step through your sub in the VB script editor (F8), you can add Range("F2").Formula to the watch window and see what the formular looks like from a VB point of view. It seems that the formular shown in Excel itself is sometimes different from the formular that VB sees...