Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel : Resize named range based on data.

Posted on 2014-09-10
3
Medium Priority
?
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 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 49

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

719 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