I'm new to VBA and I'm trying to understand how to correctly deal with current selection range referrences in VBA. I already spent an hour searching for a solution to it without success.
I used the code below (I found it in another stackoverflow post, which works fine) and changed it to use the current selection range instead of a range specified within the code as it was originally. But it´s returning 424 object required error.
mySelection variable is a Range type and so is the rng makeUpper parameter. When I inspect this variable, it has the correct content (my manually selected cell range) and correct type (range). Why isn´t it being accepted as a valid object? I read in a VBA documentation that when we skip to specify the upper levels of an object hierarchy, Excel simply assumes it should look in the currently active Workbook or Worksheet. So what am I missing?
Sub test()
' With Worksheets("Sheet1")
' makeUpper .Range("A2:A1000000")
' End With
' Changed to this...
Dim mySelection As Range
Set mySelection = Selection
makeUpper (mySelection)
End Sub
Sub makeUpper(rng As Range)
Dim v As Long, vUPRs As Variant
With rng
vUPRs = .Value2
For v = LBound(vUPRs, 1) To UBound(vUPRs, 1)
vUPRs(v, 1) = UCase(vUPRs(v, 1))
Next v
.Cells = vUPRs
End With
End Sub