May 05 2018
01:18 AM
- last edited on
Jul 31 2018
08:02 AM
by
TechCommunityAP
May 05 2018
01:18 AM
- last edited on
Jul 31 2018
08:02 AM
by
TechCommunityAP
Hi everyone! I am trying to write a nested “FOR… NEXT” loop to create the following table in Excel
Any help is much appreciated! :)
May 05 2018 01:46 AM
Hi,
You don't have to use For...Next Statement!
This formula can do that for you:
=IF(AND(ISODD(ROW()),ISODD(COLUMN())),"Odd",IF(AND(ISEVEN(ROW()),ISEVEN(COLUMN())),"Even",""))
Please copy it in cell A1, then use the fill handle to drag it to the right and down.
Regards
May 05 2018 02:03 AM
@Haytham Amairah Hi! I am actually learning how to use vba right now so that's why I was asking for a sample vba :)
May 05 2018 02:38 AM
Hi,
If so, please try this VBA code:
Sub ODD_EVEN()
'Written by Haytham Amairah
'Created: 5/5/2018
'Last updated: 5/5/2018
On Error GoTo handler
Dim appliedRange As Range
Set appliedRange = Application.InputBox("Please select the range:", , , , , , , 8)
Dim cell As Range
Application.ScreenUpdating = False
Application.EnableAnimations = False
For Each cell In appliedRange
If cell.Row Mod 2 = 0 And cell.Column Mod 2 = 0 Then
cell.Value = "Even"
ElseIf cell.Row Mod 2 <> 0 And cell.Column Mod 2 <> 0 Then
cell.Value = "Odd"
Else
cell.Value = ""
End If
Next
Application.ScreenUpdating = True
Application.EnableAnimations = True
handler:
Application.ScreenUpdating = True
Application.EnableAnimations = True
End Sub
I hope this helps you
Haytham
May 05 2018 05:35 AM
@Haytham Amairah Hi! thank you so much! It works perfectly :)