Hi,
I currently have a module in an excel workbook to go to a specific cell date in the header of columns, it also will go to the active row in relation to the matched column header date.
The question is how can the code be condensed seems if an if else statement can be used, how can the code be made more compact?
Code
Sub Button1_Click()
If ActiveCell.Row > 3 Then
'Goto current day in row
For Each Cell In ActiveSheet.Range("$AJ$3:$OI$3")
If Cell.Value = [Today()] Then
'Cell.Select
Cell.Offset(rowOffset:=ActiveCell.Row - 3, columnOffset:=0).Activate
End If
Next
End If
If ActiveCell.Row < 4 Then
'Goto current day in row
For Each Cell In ActiveSheet.Range("$AJ$3:$OI$3")
If Cell.Value = [Today()] Then
Cell.Select
'Cell.Offset(rowOffset:=ActiveCell.Row - 3, columnOffset:=0).Activate
End If
Next
End If
End Sub
Display More
Here's my attempt at an if else statement, seems very long for what looks should be less code
Code
Sub Button1_Click()
If ActiveCell.Row > 3 Then
'Goto current day in row
For Each Cell In ActiveSheet.Range("$AJ$3:$OI$3")
If Cell.Value = [Today()] Then
'Cell.Select
Cell.Offset(rowOffset:=ActiveCell.Row - 3, columnOffset:=0).Activate
End If
Next
Else
If ActiveCell.Row < 4 Then
'Goto current day in row
For Each Cell In ActiveSheet.Range("$AJ$3:$OI$3")
If Cell.Value = [Today()] Then
Cell.Select
'Cell.Offset(rowOffset:=ActiveCell.Row - 3, columnOffset:=0).Activate
End If
Next
End If
End If
End Sub
Display More
Works but doesn't look right..