I was hoping you could help me with a coding issue. I have quite a long concatenated formula that is generated via a userform in VBA. The only problem that I have with it is the Textbox6. The value entered by the user should be only 1 or 0 (that’s not the issue). The issue is when the formula is generated, the result relating to Textbox6 is “1=1” or “0=0” followed the rest of the formula. I would like the formula to identify if the Textbox6 has either a 1 or 0 and then apply the condition assigned to that value (something like: Textbox6.Value = 1 Then …). I just can’t seem to get this to work. Any help would be much appreciated.
Thanks.
ActiveCell.Formula = "=""BOX ""&IF(OR(Base_Point=1,Base_Point=2,Base_Point=3,Base_Point=4),X_Origin+" & TextBox1 & ",X_Origin-" & TextBox1 & ")&"",""&IF(OR(Base_Point=3,Base_Point=4,Base_Point=5,Base_Point=6),Y_Origin-" & TextBox2 & ",Y_Origin+" & TextBox2 & ")& "",""&IF(" & TextBox6 & "=1,Z_End,Z_Origin)&"" ""&IF(OR(Base_Point=1,Base_Point=2,Base_Point=3,Base_Point=4),X_Origin+" & TextBox3 & ",X_Origin-" & TextBox3 & ")&"",""&IF(OR(Base_Point=3,Base_Point=4,Base_Point=5,Base_Point=6),Y_Origin-" & TextBox4 & ",Y_Origin+" & TextBox4 & ")&"",""&IF(AND(" & TextBox6 & "=1,OR(Base_Point=1,Base_Point=3,Base_Point=5,Base_Point=7)),Z_End-" & TextBox5 & ",IF(AND(" & TextBox6 & "=0,OR(Base_Point=1,Base_Point=3,Base_Point=5,Base_Point=7)),Z_Origin+" & TextBox5 & ",IF(AND(" & TextBox6 & "=1,OR(Base_Point=2,Base_Point=4,Base_Point=6,Base_Point=8)),Z_End+" & TextBox5 & ",IF(AND(" & TextBox6 & "=0,OR(Base_Point=2,Base_Point=4,Base_Point=6,Base_Point=8)),Z_Origin-" & TextBox5 & "))))"
According to you comment, does this solution work for you (just replace the TextBox6 related part of your code)?
IIf(TextBox6.Value = 1, "1", "0")
You can also evaluate the "0" scenario using nested IIf function:
IIf(TextBox6.Value = 1, "1", IIf(TextBox6.Value = 0, "0", "NOT_ALLOWED_VALUE"))
How to use IIf function
Related
So this is what I want to do:
For example, in the sheet named "Outputs", the A1 cell input is
= "abcd" & Input!A5 & "efgh",
where Input!A5 is the cell value of the different sheet in the excel file.
I want to make it change so that after executing all the methods after selecting the A1 cell as
= "abcd" & Input!A5 & "efgh", I want to change the A1 cell as, = "abcd" & Input!A6 & "efgh", and then = "abcd" & Input!A7 & "efgh" and so on. (So it's basically replacing the values as A1 to Ai)
I thought of using Replace function, by writing the replacing string as Ai, and replacing i with i +1 by starting with for loop.
But I don't think this is a right method.
Could anyone shed light on how to address this?
Thanks in advance.
Check this
InputWorksheetLastRow = 7 'place here your last row value
Set ws = Worksheets("Input")
For i = 5 To InputWorksheetLastRow
Worksheets("Outputs").Range("A" & i - 4).Formula = "=" & Chr(34) & "abcd" & Chr(34) & "&Input!" & ws.Cells(i, 1).Address(0, 0) & "&" & Chr(34) & "efgh" & Chr(34)
Next i
I have a syntax error in this VBA code:
students.Cells(studentRow, StartColumn).Formula = _
"=If($" & SurnameColumnStr & studentRow & " <> """", if($" & colonnaStr & studentRow & _
" <> """", $" & colonnaStr & " & $" & pointRow & ", 0), """")"
I can't put right this piece of code: $" & colonnaStr & " & $" & pointRow & " (it would be like having "$B$3")
I've tried several ways with no luck.
Any help would be really appreciated.
To get "$B$3" out of colonnaStr (a column reference) and pointRow (a row reference), you will need to use Range.Address.
Using this inside your Formula String:
Range(colonnaStr & pointRow).Address(True, True, xlA1)
Will give you $B$3 as a result.
To learn more about is, read HERE
I have a problem with my codes below,
As you can see, I am trying to find the row value of a search. I have 3 different criteria ( they are defined before ) and 3 different ranges ( also defined before ). But I cannot find the rows unfortunately.
Here you can see the codes;
Gorev = Worksheets(WS_All).Cells(p, o).Value
SlideNo = Worksheets(WS_All).Cells(p, 34).Value
Egitim_Adi = Worksheets(WS_All).Cells(2, 3).Value
Check1 = Worksheets(j_WS).Range("A:A") 'Egitim_Adi Kontrolü için'
Check2 = Worksheets(j_WS).Range("B:B") 'SlideNo Kontrolü için'
Check3 = Worksheets(j_WS).Range("C:C") 'Gorev Kontrolü için'
Satir_bul = Evaluate("=Match(" & Egitim_Adi & " & " & SlideNo & " & " & Gorev & ", Check1 & Check2 & Check3, 0)")
I am open to any suggestion..
You have a whole heap of problems there. WorksheetFunction.Match is not going to work because you are trying to replicate an array formula so Evaluate is definitely a better bet, but you need to construct the correct formula string for it. Unless you know whether the contents of the three cells will always be text or numbers, it is easier to just use cell addresses than to worry about enclosing the values in quotes:
Gorev = Cells(p, o).address
SlideNo = Cells(p, 34).address
Egitim_Adi = Cells(2, 3).address
Satir_bul = Worksheets(WS_All).Evaluate("=Match(" & Egitim_Adi & "&" & SlideNo & "&" & Gorev & ", '" & j_WS & "'!A:A&'" & j_WS & "'!B:B&'" & j_WS & "'!C:C, 0)")
If you can limit the ranges rather than using entire columns, you'll get better performance too.
Try it like this:
Satir_bul = WorksheetFunction.Match ( Egitim_Adi & " & " & SlideNo & " & " & Gorev & ", Check1 & Check2 & Check3, 0)
Here is a bit more about Match.
It will not work. You should include Union of the ranges in Match. Read more about Unions here.
You have three strings str1, str2, str3. You have three search areas: rng1, rng2 and rng3. Now, on every range you have to do the following (cell will be range variable):
For Each cell In rng1
'here you determine if one of your strings is contained uisng InStr function
'if the above condition is satisfied, then get the number of a row
Next cell
You'll do this then with rng2 and rng3.
I'm trying to insert the following equation into a sheet:
=COUNTIFS(email_logs_output.csv!$AB$2:$AB$26731, _
usersFullOutput.csv!S26, _
email_logs_output.csv!$R$2:$R$26731, _
"<>"&"", _
email_logs_output.csv!$H$2:$H$26731, _
"gift*")
I'm getting stuck at the criteria "<>"&"". Here's what I have:
With Worksheets(users_sheet)
equation_range.FormulaR1C1 = "=COUNTIFS(" & emails_sheet & "!R2C" & email_col & ":R" & rows_email & "C" & email_col & " , RC[" & col_back & "], " _
& emails_sheet & "!R2C18:R" & rows_email & "C18, "" " <> " & "" "")"
End With
When I run it, all I get is TRUE in every cell in equation_range.
How do I get the equation to include "<>"&""?
Just tried one formula and this works
[a1].FormulaR1C1 = "=countif(R1C3,""<>"" & ""a"")"
So in your case
...C18,""<>"" & "" "")"
Notes
Basicaly, whenever you have "text" in your formula just put ""text"" and that should do the trick.
Another thing : Beware of the "autospreading" of the code in VBA environment. Check for non wanted spaces added automaticaly where you may not want them.
I am creating a formula to count based upon 2 conditions. My logic is wrong - again.
When I (manually) enter enter code the summation formula (COUNTIFS) into correct cell itself, it sums correctly:
COUNTIFS(E4:E1362,"Requirement",S4:S1362, "<>4")
When I execute the following code line, I do not get any errors, but instead, all the sums are zero.
Range("G" & Start(groups) - 1).Formula = "=COUNTIFS(E" & Start(groups) & ":E" & Finish(groups) & "," & "Requirement" & ",S" & Start(groups) & ":S" & Finish(groups) & "," & Chr(34) & "<>4" & Chr(34) & ")"
I realized that the COUNTIFS was comparing the value in column S to the string "<>4". And none of the cells contain that string. This is why all my values were zero. I do not want the comparison to be against that string. I want the comparison to be column S value NOT equal to 4.
So, I changed the line to (and variations to get it to work):
Range("G" & Start(groups) - 1).Formula = "=COUNTIFS(E" & Start(groups) & ":E" & Finish(groups) & "," & "Requirement" & ",S" & Start(groups) & ":S" & Finish(groups) & "," & Chr(34) & "<>" & Chr(34) & "4)"
So, I am at a loss. (1) I manually enter the formula and it works. (2) I build it in VBA, and it does not sum correctly. (3) I look up how to do build the formula correctly, and I get errors time and time again. It seems like the only way to get this to work is to keep the quotes within quotes, but I don't want to compare against the string.
Does this make sense? I'm not liking my worksheet anymore. It is no longer any fun at all. :(
Thank you so much.
I think all the Chr(34) are getting in the way of you viewing your formula correctly. try using "" to make the quote for the formula.
.Formula = "=COUNTIFS(E4:E1362,""Requirement"",S4:S1362,""<>4"")"
with your Start and Finish functions, that would change the formula to:
.Formula = "=COUNTIFS(E" & Start(groups) & ":E" & Finish(groups) & _
",""Requirement"",S" & Start(groups) & ":S" & Finish(groups) & ",""<>4"")"
Well, One of the problem I found there was quite simple, instead using "," you must use ";".
It depends on the version you used, some using "," and some others using ";". you can just try it, I hope it solved your problem.
and second one "Requirement" there, I think you should use double quote instead.
and for your case To meet This condition:
COUNTIFS(E4:E1362,"Requirement",S4:S1362, "<>4")
Use This:
"=COUNTIF(E" & Start(groups) & ":" & "E" & Finish(groups) & "," & """Requirement""" & "," & "S" & Start(groups) & ":" & "S" & Finish(groups) & "," & """<>4"")"
I think it Should Work (if I don't miss any Quotes thought).
... Try removing the chr(34) and the extra quotations - It should look exactly like the "Requirement" criteria:
Range("G" & Start(groups) - 1).Formula = "=COUNTIFS(E" & Start(groups) & ":E" & Finish(groups) & ",""Requirement"",S" & Start(groups) & ":S" & Finish(groups) & ",""<>4"")"
After running a quick test with your initial code
Range("G1").Formula = "=COUNTIFS(E1" & ":E20" & "," & "Requirement" & ",S1" & ":S20" & "," & Chr(34) & "<>4" & Chr(34) & ")"
Modified slightly to account for your groups variable cell G1 ends up with the following formula:
=COUNTIFS(E1:E20,requirement,S1:S20,"<>4")
which when tested works absolutely fine for your second if statement S1:S20,"<>4".
I would guess that the problem lies with your first statement. What is in your requirement range and what data are you trying to match with.
I set up the requirement named range to be cell D5, I entered a 5 in there and the formula would increment each time I added an extra 5 to the range E1:E20.
I then started typing 4's into the range S1:s20 and this decreased my count.
edit
The last thing that I can suggest is to add in a helper column in column F that evaluates row to see if it matches the requirement condition, then it would be a simple matter of making your formula:
=COUNTIFS(F1:F20,TRUE,S1:S20,"<>4")