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.
Bookmarks