Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel2K - Relative row insert in macro

Status
Not open for further replies.

thedaver

IS-IT--Management
Joined
Jul 12, 2001
Messages
2,741
Location
US
The below macro cuts an absolute Row, navigates via END:Downarrow to the end of a list, and inserts the row on the first blank line after the list.

Sub grandtotal()
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Cut
Range("C3").Select
Selection.End(xlDown).Select
Rows("35:35").Select
Selection.Insert Shift:=xlDown
End Sub

Problem, the absolute row reference for the insertion isn't going to work since my list is of variable length.

How do I alter the Rows("35:35").Select to instead select the current row (the selection after the Navigation is on the correct row for the insertion)? That way the "first blank line after the list" becomes my target insert point/row.
 
Sub grandtotal()
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Cut
Range("C3").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.Insert Shift:=xlDown
End Sub
 
Hi,

Here's the same thing with selecting a thing.

You just use range objects...
Code:
Sub grandtotal()
    Rows("2:2").Cut
    Range("C3").End(xlDown).Offset(1, 0).EntireRow.Insert Shift:=xlDown
End Sub
:-) Skip,
Skip@TheOfficeExperts.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top