Results 1 to 6 of 6

Dynamic Range VBA question

Threaded View

  1. #1
    Registered User
    Join Date
    06-09-2014
    Posts
    10

    Dynamic Range VBA question

    Hello,

    I have a question about programming dynamic ranges in VBA. I have 5 columns with a variety of different input types, including text, date and numbers. At the bottom of the list, I have two cells (separated by two blank rows) that contain subtotal and sum formulas, as well as labels, as a means of checking and filtering the data. I have set up dynamic ranges in my current program with the following code:

    Dim wb As Workbook, ws As Worksheet
        Dim lrow As Long, lcol As Long, i As Long
        Dim myName As String, Start As String
        Const Rowno = 1
        Const Colno = 1
        Const Offset = 1
        On Error Resume Next
        Set wb = ActiveWorkbook
        Set ws = ActiveSheet
        lcol = ws.Cells(Rowno, 1).End(xlToRight).Column
        lrow = ws.Cells(Rows.Count, Colno).End(xlUp).Row
        Start = Cells(Rowno, Colno).Address
        wb.Names.Add Name:="lcol", RefersTo:="=COUNTA($" & Rowno & ":$" & Rowno & ")"
        wb.Names.Add Name:="lrow", RefersToR1C1:="=COUNTA(C" & Colno & ")"
        wb.Names.Add Name:="myData", RefersTo:="=" & Start & ":INDEX($1:$65536," & "lrow," & "Lcol)"
        For i = Colno To lcol
        myName = Replace(Cells(Rowno, i).Value, " ", "_")
        If myName <> "" Then
        wb.Names.Add Name:=myName, RefersToR1C1:="=R" & Rowno + Offset & "C" & i & ":INDEX(C" & i & ",lrow)"
        End If
        Next
        
        Range("myData").Select
    The problem is that this code includes the subtotal and sum values in the range, and I do not need them to be included. How can I adjust my code to exclude these values and include only the "data"? I have attached a file to help visualize my dilemma.

    Thanks for your help.
    Attached Files Attached Files
    Last edited by bc012493; 06-09-2014 at 11:57 AM. Reason: code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Dynamic Range question
    By Woodchuck75 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-22-2012, 04:20 PM
  2. Dynamic range question
    By Guy Normandeau in forum Excel General
    Replies: 13
    Last Post: 08-02-2006, 02:35 AM
  3. dynamic range question
    By Robin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-21-2005, 07:05 PM
  4. Question regarding dynamic range setting
    By dharmik in forum Excel Formulas & Functions
    Replies: 28
    Last Post: 09-06-2005, 03:05 PM
  5. Dynamic Range Question
    By Celt in forum Excel General
    Replies: 0
    Last Post: 02-08-2005, 11:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1