lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
Selected 9 cells (3 rows/ 3 col) like below and wrote the code below. When I run the code and enter for example 5 as column number, to my surprise, it will enter hello inside column 5 which is outside my selection range. Why is that? Thank you very much.0
ps: sorry it wont allow me to correct the title
Selected 9 cells (3 rows/ 3 col) like below and wrote the code below. When I run the code and enter for example 5 as column number, to my surprise, it will enter hello inside column 5 which is outside my selection range. Why is that? Thank you very much.0
Code:
Sub myrow_selection()
Dim xcell As Range
Dim x As Integer
x = InputBox("which col")
Selection.Columns(x).Value = "hello"
For Each xcell In Selection
xcell.Interior.ColorIndex = WorksheetFunction.RandBetween(1, 56)
Next xcell
End Sub
ps: sorry it wont allow me to correct the title