exceluser999
New Member
- Joined
- Jan 7, 2018
- Messages
- 3
I need quick help. Not sure if it's possible but I'm hoping it is.
I have a loop in my code that increases the integer r by 1 with every loop. I want an IF statement within the loop in that if I press a key (eg "A"), r will increase by 1; so in that particular loop r will have increased by 2. See code example below:
Do Until r = 29
Cells(r, c).Interior.ColorIndex = 1
Cells(r, c + 1).Interior.ColorIndex = 1
Cells(r, c + 2).Interior.ColorIndex = 1
Cells(r + 1, c).Interior.ColorIndex = 1
Cells(r + 2, c).Interior.ColorIndex = 1
Cells(r + 2, c + 1).Interior.ColorIndex = 1
Cells(r + 2, c + 2).Interior.ColorIndex = 1
Cells(r + 3, c + 2).Interior.ColorIndex = 1
Cells(r + 4, c + 2).Interior.ColorIndex = 1
Cells(r + 4, c + 1).Interior.ColorIndex = 1
Cells(r + 4, c).Interior.ColorIndex = 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
This is where i want the IF statement so if at any point during the loop, the key "A" has been recognised to have been pressed then r = r + 1 here.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Allowing time for it to hold position
Application.Wait Now + TimeValue("00:00:01")
' increasing r by one
r = r + 1
Loop
I have a loop in my code that increases the integer r by 1 with every loop. I want an IF statement within the loop in that if I press a key (eg "A"), r will increase by 1; so in that particular loop r will have increased by 2. See code example below:
Do Until r = 29
Cells(r, c).Interior.ColorIndex = 1
Cells(r, c + 1).Interior.ColorIndex = 1
Cells(r, c + 2).Interior.ColorIndex = 1
Cells(r + 1, c).Interior.ColorIndex = 1
Cells(r + 2, c).Interior.ColorIndex = 1
Cells(r + 2, c + 1).Interior.ColorIndex = 1
Cells(r + 2, c + 2).Interior.ColorIndex = 1
Cells(r + 3, c + 2).Interior.ColorIndex = 1
Cells(r + 4, c + 2).Interior.ColorIndex = 1
Cells(r + 4, c + 1).Interior.ColorIndex = 1
Cells(r + 4, c).Interior.ColorIndex = 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
This is where i want the IF statement so if at any point during the loop, the key "A" has been recognised to have been pressed then r = r + 1 here.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Allowing time for it to hold position
Application.Wait Now + TimeValue("00:00:01")
' increasing r by one
r = r + 1
Loop