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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I reference a range in a macro that will change

Status
Not open for further replies.

lizI3

Programmer
Jul 2, 2002
31
0
0
CA
Hi,
Iam having trouble referencing a range in a macro that will copy and paste. If I want to copy b5 formula to C5:S5 (in excel) but later in the macro now want to copy B15 to C15:S15 how do you reference the row number so that it will pick your currect row?

Any suggests would be welcome

thanks
Liz
 
Here is one way to do what you want:
Code:
Option Explicit

Sub Macro2()
Dim nRow As Long
  nRow = ActiveCell.Row
  CopyCells nRow
End Sub

Sub CopyCells(RowNumber As Long)
  Cells(RowNumber, 2).Copy _
     Range(Cells(RowNumber, 3), Cells(RowNumber, 19))
  Application.CutCopyMode = False
End Sub
Note that if more than one cell is selected, the "ActiveCell" is the upper left-hand cell in the range.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top