I have a date switch row (Row 7) that goes False False False False True False False etc.
I want to look along the row, find the True, and then select the value in the same column but in a different row (row 70).
How can I do that?
use this formula:
=INDEX(A$70:$G$70,1,MATCH(TRUE,$A$7:$G$7,0))
where:
A$70:$G$70 is the target range (row 70)
$A$7:$G$7 is the source range (row 7)
MATCH(TRUE,$A$7:$G$7,0) gives the position (column number) of the first occurrence of TRUE in the source range
INDEX(A$70:$G$70,0,X) retrieves the value in row 1 column X (value returned by MATCH) from the target range
Related
Is it possible to hide a row if a cell has a particular value input?
ie Cell B2 has a value of 1, then hide row B4 and then if B2 = 0 then row is shown?
Something like this?
If Range("A1") = "blabla" Then
Range("A1").EntireRow.Hidden = True
Else
Range("A1").EntireRow.Hidden = False
End If
I have two columns that just have numbers in them. Every cell in column B has a number. Only certain cells in column C have a number.
I want to go down every cell in column C, check if it's empty, and if it is empty, place the adjacent column B's number minus 1 into C.
In this picture, the left two columns would be the input and the right two columns would be the desired result after the script is run(without putting it into new columns).
The B minus 1 part is the part I am having trouble with.
For Each cell In Range("C1:C20")
If IsEmpty(cell) = True Then
cell = `....`
Exit For
End If
Next cell
End If
End Sub```
Use Offset, and remove the Exit For:
For Each cell In Range("C1:C20")
If IsEmpty(cell) Then
cell.Value = cell.Offset(,-1).Value - 1
End If
Next cell
I'm trying to write a formula, which will count numbers (>0) in a row.
Only the first set of >0 numbers in a row should be counted.
When there is a 0 or an empty cell after the >0 number, the count should ignore next values.
Example:
It was fun trying to figure out a non-VBA solution.
1) Enter formula in cell H3:
=ADDRESS(ROW(B3),COLUMN(B3)+MATCH(TRUE,INDEX(B3:E3>0,0),0)-1)
It will generate a cell adress ("D3") which contains the first value > 0 in its row.
2) Enter formula in cell I3:
=MATCH(TRUE,INDEX(INDIRECT(H3):F3=0,0),0)-1
It will give you the expected result:
Requirement: one cell immediately after the data (F3) must be empty.
[Edit]: How it works
Approach logic:
for each record, find the address of the first cell that contains value > 0
starting from this cell address, find position of the first cell that is zero or blank
Desired count is a position number found at step 2, less 1
For example, for the first record step one gives "D3" - cell of the first value. Step 2 calculates that the first cell without value after "D3" starts in position 3 (D3 has value, E3 has value, F3 is blank). Therefore, value count is 3 - 1 = 2 (values in D3 and E3).
How formulas work:
INDEX(B3:E3>0,0) compares every cell in range B3:E3 to 0 (blanks are treated as 0s), and returns results as a boolean array {FALSE, FALSE, TRUE, TRUE}. MATCH(TRUE, ...) then finds position of the first TRUE in this array (3). ADDRESS calculates cell adress by adding this position to cell B3 ("B+3, 3" = "D3") .
INDIRECT(H3):F3 takes cell address we calculated in the first formula ("D3") from cell H3, and generates range D3:F3. Then MATCH(INDEX()) goes over this range and finds a position of the first cell without value (3) after D3. So, we have value in first position (D3), second position (E3), and no value in 3rd position (F3). 3 - 1 = 2 positions with values.
Create a UDF so you can loop through the columns from left to right. Place the following code in a module and use it like any other formula. It has one arguement - the range of cells on the row.
Function CountAdjacent(rng As Range)
Dim x As Integer, result As Integer
Dim ws As Worksheet
Dim firstValuePassed As Boolean
Set ws = rng.Parent
For x = rng.Column To rng.Column + rng.Columns.Count - 1
If ws.Cells(rng.Row, x) <> 0 And Not IsEmpty(ws.Cells(rng.Row, x)) Then
result = result + 1
firstValuePassed = True
Else
If firstValuePassed = True Then Exit For
End If
Next x
CountAdjacent = result
End Function
How it works:
The For loop on x goes from the first selected column to the last. If it encounters a number it increments the result by one and flags that a number has been encountered in the firstValuePassed boolean, since you want any gaps in the numbers to stop the count. If it encounters a zero or blank cell it checks against firstValuePassed to see if it comes after a number >0, if so it stops the count, if not it moves to the next cell.
What I'm attempting to do is make a list of dates in one column, and have today's date in a specific cell (=TODAY). If the date in column B matches what's in my specified cell (G12), I want the cell to the direct RIGHT of that dated cell from column B to be adjusted to the same value as what's in another cell (F13).
So if today's date is 5/17, my function or solution would check column B for that date, find the cell that has the same date, and then adjust the value of the cell to the right of that date to whatever would be the same as cell (F13). So if cell (F13) has the value of 56, my spreadsheet would check today's date, find that cell in column B and adjust the cell to the right of it to be the same as F13 (56).
I hope that makes sense. I have some experience in VBA if that's what is needed to accomplish this. I'd like to make it automated as much as possible.
Use AutoFilter to filter for today's date on column B and if there are visible cells, set column C to the value in F13.
With worksheets("sheet1")
If .AutoFilterMode Then .AutoFilterMode = False
With .Cells(1, "A").CurrentRegion
.AutoFilter Field:=2, Criteria1:=date
With .Resize(.Rows.Count - 1, .Columns.Count).Offset(1, 0)
If CBool(Application.Subtotal(103, .Cells)) Then
.specialcells(xlcelltypevisible).offset(0,1) = .parent.cells(13, "F").value2
End If
End With
End With
If .AutoFilterMode Then .AutoFilterMode = False
End With
I am trying to write a VBA script on Excel 2011 For Mac and having limited success.
Depending on the value in cell A1, the script needs to unhide the rows below.
If A1 = 1, it needs to unhide row B.
If A1 = 2, it needs to unhide rows B and C.
If A1 = 3, it needs to unhide rows B, C and D.
...and so on, up to a maximum A1 value of 8.
The values in A1 use data validation to be looked up from a list elsewhere on the sheet.
Thank you!
If you say B, C, D, it seems you mean Columns, not Rows.
You can use this:
Range("B1").Resize(1, Range("A1")).EntireColumn.Hidden = False
Select Case Range("A1").Value
Case 1
Range("A2").EntireRow.hidden = false
Case 2
Range("A2,A3").EntireRow.hidden = false
'...
Case Else
MsgBox("Invalid number in cell A1")
End Select
in this case A2 would refer to row 2, A2,A3 would be 2 and 3 etc etc
EDIT:
per your comment maybe something like this would be better
Dim rng as Range
Dim val as Integer
val = Range("AE25").Value
if (val >= 1) then
set rng = Range("A26:A27").Resize(val,0)
rng.EntireRow.Hidden = false
end if