Solved

Excel : Resize named range based on data.

Posted on 2014-09-10
3
174 Views
Last Modified: 2014-09-11
Hi
I have a sheet with a named range. (with 1 data line and 1 headline)
I have to a sheet with data in it.

If I resizes the range with the mouse, I get this code udsing record macro :
Sub Makro1()
    ActiveSheet.ListObjects("Tabel99").Resize Range("$A$3:$D$14")
End Sub

Open in new window

BUT, I need a VBA code that resizes the Range based on data lines fra the data sheet.
In this case not row 14 but 16......

Attached : Excel
EE-Example.xlsm
0
Comment
Question by:conceptdata
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 40314839
This will resize to the same size as the table on the other sheet:
Sub Makro1()
    Dim lngLastRow As Long
    Dim oList As ListObject
    
    With Sheets("C5_InvenItemGroup").ListObjects(1).DataBodyRange
    lngLastRow = .Row + .Rows.Count - 1
    End With
    ActiveSheet.ListObjects("Tabel99").Resize Range("$A$3:$D$" & lngLastRow)
End Sub

Open in new window

0
 
LVL 2

Expert Comment

by:Rolf Hasselbusch
ID: 40314861
Here you'll find Examples for Dynamic Ranges as Formulas and in VBA (at the bottom).

If you need further assistance i hope some more VBA addicted Experts take a look at this question.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40315939
Here are two formulas for dynamic ranges. In this case the data is in column A.

Range has no heading
=OFFSET('Sheet Name'!$A$1,0,0,COUNTA('Sheet Name'!$A:$A),1)

Range has a heading
=OFFSET('Sheet Name'!$A$2,0,0,COUNTA('Sheet Name'!$A:$A)-1,1)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now