drop first row in range and return a new range object

R

Rik

Hi I'm trying to create a function that will drop the first row in a given
range object and return a new range object - to eliminate headers from a
range object.

so something like this???

Function dropFirstCell(ByVal r As Range) As Range
Dim r2 As Range
Dim i As Integer

i = 2
Set r2 = r.Range(Cells(i), Cells(r.Rows.Count))

Set dropFirstCell = r2

End Function

can anyone help?
 
G

Gary''s Student

We build the output range one cell at a time:

Function rout(rin As Range) As Range
Set r1 = rin.Cells(1, 1)
rw1 = r1.Row
Set rout = Nothing
For Each rr In rin
If rr.Row = rw1 Then
Else
If rout Is Nothing Then
Set rout = rr
Else
Set rout = Union(rout, rr)
End If
End If
Next
End Function


Sub tester()
Dim r As Range
Set r = Range("A1:F7")
MsgBox (rout(r).Address)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top