Auto-Adjusting VBA Range
Auto-Adjusting VBA Range
#FreeTrial ×
TOOLS
5 Wa to Create A
Dnamic Auto-
Search
Adjuting VA Range
May 25, 2015 Chris Newman
Sub DynamicRange()
'Best used when only your target data is on
the worksheet
Latest VBA Code Vault Posts
'Refresh UsedRange (get rid of "Ghost" cells)
Worksheets("Sheet1").UsedRange
VBA Code To Loop Through Only
'Select UsedRange
Worksheets("Sheet1").UsedRange.Select Selected Excel Charts
4 WEEKS AGO
End Sub
This code simulates the range that would show up if you Microsoft Word VBA To Save
were to use the keyboard shortcut Ctrl + Shift + Right Document As A PDF In Same Folder
Arrow and then Ctrl + Shift + Down Arrow. If the last cell A MONTH AGO
in the first row or the last cell in the first column are
empty, this code will not calculate properly.
Free Webinars
Sub DynamicRange()
'Best used when first column has value on
last row and first row has a value in the
last column
'Select Range
sht.Range(StartCell, sht.Cells(LastRow,
LastColumn)).Select
End Sub
Sub DynamicRange()
'Best used when you want to include all data
stored on the spreadsheet
'Refresh UsedRange
Worksheets("Sheet1").UsedRange
This example uses the CurrentRegion method. 5 Different Ways to Find The Last
CurrentRegion tries to calculate the range associated Row or Last Column Using VBA
with a cell reference by analyzing the surrounding cells. If 2 YEARS AGO
Sub DynamicRange()
'Best used when your data does not have any
entirely blank rows or columns
End Sub
Like Page
Sub DynamicRange()
'Best used when column length is static
'Refresh UsedRange
Worksheets("Sheet1").UsedRange
'Select Range
sht.Range("D9:M" & LastRow).Select
End Sub
Chances are this post did not give you the exact answer
you were looking for. We all have different situations and
it's impossible to account for every particular need one
might have. That's why I want to share with you: My
Guide to Getting the Solution to your Problems FAST! In
this article, I explain the best strategies I have come up
with over the years to getting quick answers to complex
problems in Excel, PowerPoint, VBA, you name it!
I wish you the best of luck and I hope this tutorial gets
you heading in the right direction!
Comments Community
1 Login
Sort by Best
Recommend 2 ⤤ Share
Ejaz
9 months ago
− ⚑
Guy
4 months ago
− ⚑
Hi everybody!
I am trying to import data from one workbook to
another using the code below, but it returns the
message "Run-time error `1004`: Application-defined
or object-defined error".
The number of columns is always the same and the
rows can vary.
Sub DATA()
Target_Path = "C:\database.xls"
Set Target_Workbook =
Workbooks.Open(Target_Path)
see more
△ ▽ Reply
sudha
4 months ago
− ⚑
HI,
I am making a dash board for recruitment of my
company.I need help.I have 12 sheets namely april ,
may ,june...till march , in each sheet there are several
columns such as name email id contact etc and final
columns such as name email id contact etc and final
feedback.
i want a macro or something that dynamically adds
few fields like name, experience , email id of only
selected candidates to a new work book so that other
values like offer date etc can be filled manually.
I will be glad if someone could help me for the same.
△ ▽ Reply
Ramesh
5 months ago
− ⚑
Sub Dynamic_Range()
Dim i, j As Integer
Worksheets("Faces").Select
For i = 1 To Rows.Count
For j = 1 To Columns.Count
If Cells(i, j).Value <> "" Then
Cells(i, j).Select
Exit For
End If
Next j
If Selection.Value <> "" Then
Exit For
End If
Next i
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection.End(xlToRight),
Selection.End(xlDown)).Select
end sub
△ ▽ Reply
Mikey1969
7 months ago
− ⚑
Kishorekumar
− ⚑
8 months ago
Sub FormulaInsertion()
see more
△ ▽ Reply
−
Alejandro
8 months ago
deepak gaba
− ⚑
8 months ago
△ ▽ Reply
Rob
− ⚑
8 months ago
cathig33
9 months ago
− ⚑
of how many rows and columns I need in the range.
I'm using COUNTIF formulas for that.
△ ▽ Reply
Sweet! It worked!
column count in cell A3 on a worksheet called
Report.
1△ ▽ Reply
Ian Chapman
− ⚑
9 months ago
Probably a silly question Chris, but do you write vba
code for specific bespoke needs?
△ ▽ Reply
Chris > Ian Chapman
− ⚑
9 months ago
Ian Chapman
− ⚑
9 months ago
△ ▽ Reply
ALSO ON THESPREADSHEETGURU