0
Cell A1 can be filled in with whole number values
I want that if Cell A1 is less than 10 then B1 says'<10' I want that if Cell A1 is between 10 and 25 then B1 says'10-25' I want that if Cell A1 is more than 25 then B1 says'>25' however if A1 is blank then B1 should also be blank
I have the formula working to show the correct value however I cannot get B1 to show blank if A1 is blank.
I will be happy to use normal formulas or even VBA for this to work.
Any help is appreciated
How about this formula?
=IFERROR(INDEX({"<10","10-25",">25"},MATCH(A1,{1,10,25})),"")
The above formula will show a blank for numbers <1. If you need to evaluate such numbers as "<10" start the MATCH() array at 0 instead of 1.
Test blank first:
=IF(A1="","",IF(A1<10,"<10",IF(A1>25,">25","10-25")))
for vba you could try this:
Private Sub Worksheet_change(ByVal Target As Range)
Set Target = Application.Intersect(Target, Range("A1"))
If Not Target Is Nothing Then 'if action is not NOT happening in A1, do something...
Select Case Range("A1")
Case "": ActiveSheet.Range("B1").Clear
Case Is < 10: ActiveSheet.Range("B1").Value = "<10"
Case Is < 25: ActiveSheet.Range("B1").Value = "10-25"
Case Else: ActiveSheet.Range("B1").Value = ">25"
End Select
End If
End Sub
Try this -
Cell B1 formula:
=IF(ISBLANK(A1),"",IF(A1<10,"<10",IF(AND(A1>=10,A1<=25),"10-25","")))
To also show "25+" when A1 > 25, use this instead.
=IF(ISBLANK(A1),"",IF(A1<10,"<10",IF(AND(A1>=10,A1<=25),"10-25",IF(A1>25,"25+",""))))
Related
I have a macro to colour a cell based on the RGB values.
I have cells A1, B1, and C1 for the RGB values.
Sub FillWithRBG()
Range("D1").Interior.Color = RGB(Range("A1").Value, Range("B1").Value, Range("C1").Value)
End Sub
I can select anywhere in the worksheet, run the macro and only cell D1 will change colour.
I want to select cell D2, run the macro and Cell D2 changes colour based off values in A2, B2, and C2.
I imagine I need to set the active cell with a reference, then 1, 2 and 3 will be offset from the selected cell.
An added bonus would be that the macro can only run in the D column to prevent errors.
This would be a simple approach
In the code Me. is refering to the current sheet
You have to place this code in the sheet's module
Columns in VBA are noted by numbers (so column A is referenced as column 1)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' Prevent change if changed values are no in these columns (1,2,3) numbers are equivalent to A, B, C
If Target.Column > 3 Then Exit Sub
' Change color of D column (4 = D)
Me.Cells(Target.Row, 4).Interior.Color = RGB(Me.Cells(Target.Row, 1).Value, Me.Cells(Target.Row, 2).Value, Me.Cells(Target.Row, 3).Value)
End Sub
If you want it to work only if you're changing one cell at a time add these lines:
' Prevent change when more than one cell is changed
If Target.Cells.Count > 1 Then Exit Sub
I am trying to write a formula that allows me to calculate a formula that has two variables. I want to be able to enter either variable A and have it calculate B, OR enter variable B and have it calculate A.
Formula to calculate my variables:
Value = NOI / CAP
CAP = NOI / Value
Value is in cell A1
NOI is in cell A2
CAP is in cell A3
NOI is a known value. I want to have separate cells for Value and CAP, and be able to enter data into either cell and have the other cell compute based on my data entry.
I was going to try an IF function with an ISBLANK, but I'm not sure how to do this that won't overwrite the formula.
You can have a formula, or enter a value, but you can't do both. The workaround is to use the Worksheet_change event to monitor each of the two cells and set the other one according to any entered value.
This would go in the worksheet code module:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Goto haveError:
If Target.Address = "$A$2" Then
Application.EnableEvents = False
Me.Range("A3").Value = 'set value in A3
Application.EnableEvents = True
End If
If Target.Address = "$A$3" Then
Application.EnableEvents = False
Me.Range("A2").Value = 'set value in A3
Application.EnableEvents = True
End If
Exit sub
haveError:
'make sure events are re-enabled if an error occurs
Application.EnableEvents = True
End Sub
As an alternate approach you can enter the number in cell A1. In Cell A2 State if it is Cap or Value. In Cell A3 place your NOI. Since the formula is essentially the same for both cases you can simply use the following in A4:
=A3/A1
In B4 I would place the following to indicate which value it was:
=IF(A2="Value", "CAP", IF(A2="CAP","Value", "Enter Type in A2"))
However if you absolutely want data entry in A1 or A2 and then have the other cell get calculated then your only approach is VBA as Tim Williams has pointed out.
There is a way to do this without macros using the ISFORMULA() function, which is available in Excel 2013 or later. The trick is ISFORMULA() can query the state of a cell without actually evaluating it's value, and so can be used to direct a formula to avoid referring to that cell and causing a circular reference.
To wit:
A1 is Value, A2 is NOI (which is given) and A3 is CAP
A1: =IF(NOT(ISFORMULA(A3)), A2 / A3, "")
A2: 123.456
A3: =IF(NOT(ISFORMULA(A1)), A2 / A1, "")
Both A1 and A3 will remain blank until you enter a value in either one of them, at which time the other will be calculated appropriately.
Here are snippets of two worksheets
This is the code that I have on the first sheet meant for change in selection of the dropdown. There will be more Cases, but my issue is with the SUMIF. Anytime column B on Sheet2 matches the corresponding column A item on Sheet2, sum column C on Sheet2.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D1")) Is Nothing Then
Select Case Range("D1")
Case "2014-2015": Cells(2, "B") = WorksheetFunction.SumIf(Worksheets("2014-2015").Range("B2:B22"), A2, Worksheets("2014-2015").Range("C2:C22"))
Case Else: Cells(2, "B") = 8
End Select
End If
End Sub
The problem is that it is always returning 0. Hoping for help as to an edit to the code to make it display the proper total.
Thanks,
It looks like the problem is with the value it is trying to match, specified only as A2 in your Sumif formula. It isn't recognizing that you want to match the value in cell A2. It would need to be referenced with something similar to Worksheets("SummarySheet").Range("A2").Value like you did for the other parameters of that function.
**I am counting strings like if a word is appearing 10 times. then that word is in cell a1 and count is in cell a2 ** - I am generating this from code...(SUM((LEN(range_chk)-LEN(SUBSTITUTE(UPPER(range_chk),UPPER(Sheet2!E8),"")))/LEN(Sheet2!E8))
) ( My data is in sheet1 and I am finding words in sheet2 ....FYI - range_chk is a offset function used in excel through name manager---and this code works fine)
I have tried worksheet_change(byval target as range) function but its going in loop.
please help on code.
What I need is
I am finding word : in cell A1: Me
I am getting count : in Cell A2: 5
cutting from above cells n pasting it in
Cell A7 --"Me" Cell B7---"5"
Next searched word: "Really" with count 3
cut n Paste in Cell A8 --"Really" Cell B8-- 3
Next Searched word: "sense" with count 6
cut n Paste in Cell A9 --"sense" cell B9 --6 ....and so on.
Then sort the range from A7:B9 according to count in ascending order.
If you want to use the Worksheet_Change method do this and it will stop looping:
It's looping because another thing on the worksheet changes when you run your code.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
'Your code here
Application.EnableEvents = True
end sub
I would like to do the following: Whenever anything in cell A2, A3, A4 is changed, the corresponding date in cell B2, B3, B4 should be updated to the current date. If nothing is done in A2, A3, A4, the dates in B2, B3, B4 should not be updated.
Any ideas how to accomplish that?
For reference pls. see the screenshot
I would use VBA and the worksheet's Change event. Here's a simple example that works on column A except the first row
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Row > 1 Then Target.Offset(0, 1) = Now()
End Sub
The resulting time format can be changed through Format.