Alex Piotto
Board Regular
- Joined
- Jul 5, 2016
- Messages
- 82
- Office Version
- 2007
- Platform
- Windows
Hi Everyone!
I need to select a dynamic range of columns values, sum the values and show them in another cell.
The script below
will select the dynamic cell range horizontally right, but also vertically. Ho to avoid it?
I need to select a dynamic range of columns values, sum the values and show them in another cell.
The script below
VBA Code:
Sub DynamicRange()
Dim sht As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range
Set sht = ActiveSheet
Set StartCell = Range("F5")
ActiveSheet.UsedRange
'Find Last Row and Column
LastRow = StartCell.SpecialCells(xlCellTypeLastCell).Row 'NO THANKS....
LastColumn = StartCell.SpecialCells(xlCellTypeLastCell).Column
'Select Range
sht.Range(StartCell, sht.Cells(LastRow, LastColumn)).Select
End Sub
will select the dynamic cell range horizontally right, but also vertically. Ho to avoid it?