I would like to colour a users defined selection in Excel and then add a text entry to the last cell of the selection.
So far I have the selection but sorted but struggling on the text entry.
Dim Cell As Object
Sheets("Jobs").Activate
For Each Cell In Selection
Cell.Interior.Color = RGB(255, 192, 0)
Next Cell
CodePudding user response:
You can just set a range object on every loop which will end up being the last one by the time it's done ...
Dim Cell As Range, objLastCell As Range
Sheets("Jobs").Activate
For Each Cell In Selection
Cell.Interior.Color = RGB(255, 192, 0)
Set objLastCell = Cell
Next Cell
objLastCell.Value = InputBox("Enter some text and I'll throw it in cell " & objLastCell.Address & " ...", "Enter Text")
... something like that anyway.
Also, this assumes the last cell is the last selected, not the last (i.e. the bottom right) cell in the selection.
