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

Assign an Excel Row to a VBA variable 1

Status
Not open for further replies.

anet

Programmer
Jul 10, 2001
35
CA
I am copying cells from one worksheet to another. If I hard code in a cell address it works fine. But I want to copy only certain cells from a row that the user selects. How do I assign the row ID to a variable.

Here is the code that I have so far:

Private Sub cmdPaySlip_Click()

Dim myRow As String 'is this the right datatype?

If Selection.Rows.Count = 1 And Selection.Columns.Count > 2 Then
'myRow = ????????? how do I do this?
Range(myRow, 4).Select 'is this right?
Selection.Copy
Sheets("Pay Slip").Select
ActiveSheet.Range("B6").Select
ActiveSheet.Paste
Else
MsgBox ("Please select a week to process.")
End If
End Sub
 
Not sure what you are trying to do. This example should help, I think:

dim MyRow as integer
MyRow = selection.row
cells(MyRow,4).copy Sheets("Pay Slip").Range("B6")

Rob

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top