Modify a script to select only the dynamic row

Alex Piotto

Board Regular
Joined
Jul 5, 2016
Messages
82
Office Version
  1. 2007
Platform
  1. 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
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?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
How about
VBA Code:
Range("F5", Cells(5, Columns.Count).End(xlToLeft)).Select
 
Upvote 0
Thanks Fluff. Actually now I need to sum the values inside the selected range...
and I have lots of rows below with the same needs...
Range is not F5 is I6 my mistake.
I may need a loop? I am veeery uneasy with loops...
 
Upvote 0
In that case I would suggest you tell us exactly what you are trying to do, rather than some simplified version.
 
Upvote 0
Hi again. I finally find a workaround and i got it to work.
I forgot I already had the values I needed in another sheet, so I just used them.
Sorry... getting old!
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,881
Messages
6,122,074
Members
449,064
Latest member
MattDRT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top