I have inserted a check box (form control) with the title "wall".
Next to this I have the cell stating "False" if unticked and "True" if ticked.
Next to this are two cells with the dimensions of the wall "length", "height". - Lastly is the cell containing "area of the wall".
I want to write an IF statement in the "area of the wall" cell so that when the check box IS ticked, the area of the wall is printed, and if it is NOT ticked it prints N/A If have written:
=IF((C2="TRUE"), (D2*E2), ("N/A"))
All that happens is the cell reads N/A, no matter whether the box is ticked or not. Any help please on how to correct this? Example
True should not be in quotes, it's treating it like a string when it's a boolean. Removing the quotes should work or writing TRUE()
The final formula should look like this:
=IF((C2=TRUE), (D2*E2), ("N/A"))
Related
I'm having trouble figuring this out, I've inserted an IF statement into my code but my fields are still showing 0's where there are blanks in my table. Any help would be appreciated!
=IFERROR(INDEX('Error'!$A$2:$I$5000,SMALL(IF('Error'!$E$2:$E$5000="","",IF(OR('Error'!$E$2:$E$5000="does
not match",'Error'!$A$2:$I$5000="not on the
Route"),ROW('Error'!$A$2:$A$5000))),ROW(2:2))-1,1),"")
Edited to include expected results and table
If the purpose of your function is to determine if at least one cell in your range is empty, you can use the COUNTBLANK() function like this :
=IF(COUNTBLANK('Error'!$E$2:$E$5000) > 0, "at least one is empty", "no empty cell")
I needed to add the condition at the very beginning of the code to make this work, so there are now essentially two index/small conditions. Blank values now populate as expected.
{=IFERROR(IF(INDEX('Error Report'!$A$2:$I$5000,SMALL(IF(OR('Error Report'!$E$2:$E$5000="Dealer does not match the shipment",'Error Report'!$A$2:$I$5000="Dealer ID is not on the Route"),ROW('Error Report'!$A$2:$A$5000)),ROW(4:4))-1,1)="","",INDEX('Error Report'!$A$2:$I$5000,SMALL(IF(OR('Error Report'!$E$2:$E$5000="Dealer does not match the shipment",'Error Report'!$A$2:$I$5000="Dealer ID is not on the Route"),ROW('Error Report'!$A$2:$A$5000)),ROW(4:4))-1,1)),"")}
I'm using In-Cell-Dropdown in Excel cell, I want Default value "Select" should be shown in the dropdown cell always,If there is no value is selected. please let us know, how to achieve that.
In validation source I have tried that using offset formula, but expected result didn't come. this is the formula I tried.
=IF($F$4=44,OFFSET($Y$4,0,0,Counta($Y$4:$Y$6) -1,1),OFFSET($S$4,0,0,Counta($S$4:$S$8)-1,1))
Try this,
Step 1 : Insert a rectangular shape and refer the shape text from some other cell
Step 2 : Write a formula in the cell that you've referred in the shape
Step 3 : Lock the shape so it doesn't get deleted and then when you select value default selection will disappear and when you delete selection it will appear again.
P.S : If you don't need to retain value after the initial selection you can write a formula like this.
P.s :
I am trying to use the substitute function in Excel to change the 05 in the first column to 04 as follows:
06-05NG22D021 --------------- 04NG22D021
06-05NG22D021-KP01 ---------- 06-04NG22D021-KP01
06-05NG22D021-M01 ----------- 06-04NG22D021-M01
06-05NG22D021-MK01 ----------- 06-04NG22D021-MK01
The problem is that when I use:
=SUBSTITUTE(A1, "-05", "-04")
it does not change the text to what it is supposed to be, it only changes when I remove '-0' like this
=SUBSTITUTE(A1, "5", "4")
it works correctly. The thing is that I have to include the '-0' in the string to ensure that the right part of the text is changed.
Sometimes it's because the cell or the column is locked.
Or also it can be the Format cells number category.
To unlock:
Right click on the cell or the column and in the "Format cells" window go to tab "Protection", uncheck "Locked" if checked.
To change format cells number category:
Right click on the cell or the column and in the "Format cells" window go to tab "Number", change category to "General" especially if "Text" is already selected.
Return to your cell and re-apply the formula.
You may be able to bypass the issue with:
=REPLACE(A1,5,1,4)
(copied down to suit) where the second parameter is the 5th character in A1 (which just happens to be 5).
REPLACE.
(Does not work for first row in your example however.)
I'm writing a tool that syncs a simple database with Excel sheets. Each item in a table in the database corresponds to one row in the worksheet. I read the Excel sheet into the tool using C# and the Excel interop com interface, then compared the items' values (i.e. one of the columns in the excel sheet) after the sync just to make sure that they are equal.
Yesterday I found a case where the comparison wasn't true:
"'<MedalTitle>' Medal - <MedalDescription>"
"<MedalTitle>' Medal - <MedalDescription>"
The second is the one I've read in from Excel, and as you can see it's skipped the first apostrophe. Is there a way to tell Excel to treat the cell as just text (no, just setting the cell's formatting doesn't help)?
I even tried to copy the value ( 'hello' ) of a cell in VBA like this:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Target.Offset(1, 0).Value = Target.Worksheet.Range("b2").Value
Target.Offset(2, 0).Value = Target.Worksheet.Range("b2").Formula
Target.Offset(3, 0).Formula = Target.Worksheet.Range("b2").Formula
Target.Offset(4, 0).Formula = Target.Worksheet.Range("b2").Value
End Sub
The result was that the value of target cell is always hello'
If there is no way, I'll have to do something ugly like
if (dbitem.value[0] == ''' )
{
// stuff
}
else
{
// regular comparison
}
I'm afraid the apostrophe ' is a special character for Excel when it appears as the first character in a cell as you've found. It tells Excel to treat the rest of the string as text, so that you can enter something like '34.2 in the cell, and it'll treat it as the string instead of the number (for formatting and so on).
I suggest doing something similar to what you've suggested, except that where you're putting it into Excel, check the first character, and add an extra ' if there's one there already.
Alternatively, you could prepend an apostrophe to all values - if you want them all as text that is. That way you don't need the extra first character check.
Look at the PrefixCharacter property of the Range object which corresponds to that cell
From the help:
If the TransitionNavigKeys property is
False, this prefix character will be '
for a text label, or blank. If the
TransitionNavigKeys property is True,
this character will be ' for a
left-justified label, " for a
right-justified label, ^ for a
centered label, \ for a repeated
label, or blank.
The TransitionNavigKeys part relates to Lotus 1-2-3 compatibility so it's more than likely going to be False
Answer based on article at:
http://excel.tips.net/Pages/T003332_Searching_for_Leading_Apostrophes.html
(warning: slightly annoying pop-up may appear)
edit: actually this probably isn't going to be any use because PrefixCharacter is read-only :(
edit2: I was right the first time. PrefixCharacter only gets populated if the value added to the cell started with ' so just read back PrefixCharacter plus Value and concatenate. As long as TransitionNavigKeys is False, that is
try targetcell.Value instead. .Formula is the formula seen in the formula bar while .Value is the evaluated value of the cell.
So, I am guessing that you would have used .Formula in your original code as well. Changing that should work.
EDIT: Ok, it did not work (embarrassed).
Excel treats the starting single quote specially.. so specially that even obscure cell / range properties do not have access. The only workaround I could find is essentially the same as what you thought initially. Here goes:
If VarType(cell) = 8 And Not cell.HasFormula Then
GetFormulaI = "'" & cell.Formula
Else
GetFormulaI = cell.Formula
End If
You might try pre-pending a single quote to your text fields ( '''' + dbField ) in your query so that for fields with embedded single quotes your query would return:
"''stuff in single quotes'"
which when placed in an Excel cell would convert to:
"'stuff in single quotes'"
for characters that weren't in quotes you would get:
"'stuff that wasn't in quotes"
which when placed in an Excel cell would convert to:
"stuff that wasn't in quotes"
Worth a shot. :-)
I am writing a quick application myself - first project, however I am trying to find the VBA code for writing the result of an input string to a named cell in Excel.
For example, a input box asks the question "Which job number would you like to add to the list?"... the user would then enter a reference number such as "FX1234356". The macro then needs to write that information into a cell, which I can then use to finish the macro (basically a search in some data).
You can use the Range object in VBA to set the value of a named cell, just like any other cell.
Range("C1").Value = Inputbox("Which job number would you like to add to the list?)
Where "C1" is the name of the cell you want to update.
My Excel VBA is a little bit old and crusty, so there may be a better way to do this in newer versions of Excel.
I recommend always using a named range (as you have suggested you are doing) because if any columns or rows are added or deleted, the name reference will update, whereas if you hard code the cell reference (eg "H1" as suggested in one of the responses) in VBA, then it will not update and will point to the wrong cell.
So
Range("RefNo") = InputBox("....")
is safer than
Range("H1") = InputBox("....")
You can set the value of several cells, too.
Range("Results").Resize(10,3) = arrResults()
where arrResults is an array of at least 10 rows & 3 columns (and can be any type). If you use this, put this
Option Base 1
at the top of the VBA module, otherwise VBA will assume the array starts at 0 and put a blank first row and column in the sheet. This line makes all arrays start at 1 as a default (which may be abnormal in most languages but works well with spreadsheets).
When asking a user for a response to put into a cell using the InputBox method, there are usually three things that can happen¹.
The user types something in and clicks OK. This is what you expect to happen and you will receive input back that can be returned directly to a cell or a declared variable.
The user clicks Cancel, presses Esc or clicks × (Close). The return value is a boolean False. This should be accounted for.
The user does not type anything in but clicks OK regardless. The return value is a zero-length string.
If you are putting the return value into a cell, your own logic stream will dictate what you want to do about the latter two scenarios. You may want to clear the cell or you may want to leave the cell contents alone. Here is how to handle the various outcomes with a variant type variable and a Select Case statement.
Dim returnVal As Variant
returnVal = InputBox(Prompt:="Type a value:", Title:="Test Data")
'if the user clicked Cancel, Close or Esc the False
'is translated to the variant as a vbNullString
Select Case True
Case Len(returnVal) = 0
'no value but user clicked OK - clear the target cell
Range("A2").ClearContents
Case Else
'returned a value with OK, save it
Range("A2") = returnVal
End Select
¹ There is a fourth scenario when a specific type of InputBox method is used. An InputBox can return a formula, cell range error or array. Those are special cases and requires using very specific syntax options. See the supplied link for more.
I've done this kind of thing with a form that contains a TextBox.
So if you wanted to put this in say cell H1, then use:
ActiveSheet.Range("H1").Value = txtBoxName.Text