MuchToLearn
New Member
- Joined
- Dec 15, 2008
- Messages
- 31
- Office Version
- 2019
- 2016
- 2013
- 2010
- Platform
- Windows
I know this is very simple problem for the people who provide helps here. I got a bit lost when I was practicing some VBA coding.
If say I want to fill cells A1:G1 & A2:E2 with values. At first, I put
Then I though it’s kind of double handling with filling in values, then remove some of them, so I tried.
But not really work as I expected, the whole of range A1:G2 got filled. I don’t understand enough about the Excel VBA now to know why. So, this my first question.
Declare a separate range for A2:E2 adds to code too. Is there a simpler solution? That’s my second question.
If say I want to fill cells A1:G1 & A2:E2 with values. At first, I put
VBA Code:
Sub FillRange1()
Dim RngCellUnit, RngRangToFill As Range
Set RngRangeToFill = Range("A1:G2")
For Each RngCellUnit In RngRangeToFill
RngCellUnit.Value = 1
Next RngCellUnit
Range("F2:G2") = ""
End Sub
VBA Code:
Sub FillRange2()
Dim RngCellUnit, RngRangeToFill As Range
Set RngRangToFill = Range("A1:G1", "A2:E2")
For Each RngCellUnit In RngRangToFill
RngCellUnit.Value = 1
Next RngCellUnit
End Sub
Declare a separate range for A2:E2 adds to code too. Is there a simpler solution? That’s my second question.