1

I am trying to create this loop inside the loop so as to print inside the cells in the below range -> Week i where i is from 1 to 6 and it raises by one each time we move to a cell down...

So, in this case, for D2 I want Week 1, For D3 Week 2 etc.. Any ideas? I appreciate your time!

 Sub INPUT()
        Sheets("1").Select 
        For Each cell In range("D2:D7")
        For i = 1 To 6
        cell.Value = "Week +" & i
        i = i + 1
        Next i
        Next cell
End Sub
1
  • The answer below obviously gives you the code you need. But purely as a FYI, the problem with your code above is that you don't need the i=i+1. The incrementing is managed by the `For i = 1 to 6' and 'next i'. Commented Aug 22, 2017 at 22:47

1 Answer 1

2

You only need the one loop:

Sub INPT()
    With Sheets("1")
        i = 1
        For Each cell In .Range("D2:D7")
            cell.Value = "Week +" & i
            i = i + 1
        Next cell
    End With
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

i starts counting from 0.. can I make it start from 1 because first week appears as Week + (empty)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.