Forum Discussion
Variable Cell Reference
Hi,
Your code doesn't work and contains unnecessary objects!
If you want to change the cells A1, K2 and H7 to have the value of "Hello"
Simply, you just need to this one:
Sub process()
Range("A1,K2,H7").Value = "Hello"
End Sub
But please clarify your problem with some screenshots!
The cells that you want to change contain values and you want to replace them with the value of "Hello" ???
Or it's just blank cells?
Is the day1 to day37 values are the header of these cells that you want to change?
- hsbign15Jan 13, 2018Copper Contributor
I do not simply want to directly add the cells inside Range(). I want to add an integer to "day" and use that to reference day1, day2, day3, etc. which are the different cells to change. I need it this way so that I can change the number of iterations within the For loop. For example:
Dim days As Integer
days = 31
Dim day1 As String
day1 = "A1"
Dim day2 As String
day2 = "K2"
Dim day3 As String
day3 = "H7"
Dim day4 As String
day4 = "G4"
..........All the Way to day37 with different cell values......
For k = 1 To days
Range(day & k).Value = "Hello"
Next k
-------------------------------------------------------------
In the example (which doesn't work), I want all the cells that are referenced in the day1, day2, day3, all the way to "day & days" to have the value "Hello". This way I can change the number of iterations of the For loop by changing the days variable. Also, if I want all I have to do is change the value of day1, day2, etc. instead of having to manually change the cells within Range() in my entire code.
- Haytham AmairahJan 13, 2018Silver Contributor
I tried to find a solution for you, but I could not.
Try to post your request https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel, this the best place to get support!