David Cates
New Member
- Joined
- Mar 10, 2009
- Messages
- 9
the following procedure produces a run-time error 9: subscript out of range
on the line r1 = Worksheets("Addresses").Range("A2").CurrentRegion.Select
What is wrong? Using Excel 2007
Public Sub EnterDataInWorksheet()
' Copies data from the user form
' to the next blank row in the worksheet.
Dim Addresses As Worksheet
Dim r As Range, r1 As Range
r1 = Worksheets("Addresses").Range("A2").CurrentRegion
Set r1 = r.Offset(r.Rows.Count, 0)
r1.Cells(1).Value = txtFirstName.Value
r1.Cells(2).Value = txtLastName.Value
r1.Cells(3).Value = txtAddress.Value
r1.Cells(4).Value = txtCity.Value
r1.Cells(5).Value = cmbStates.Value
r1.Cells(6).Value = txtZip.Value
End Sub
on the line r1 = Worksheets("Addresses").Range("A2").CurrentRegion.Select
What is wrong? Using Excel 2007
Public Sub EnterDataInWorksheet()
' Copies data from the user form
' to the next blank row in the worksheet.
Dim Addresses As Worksheet
Dim r As Range, r1 As Range
r1 = Worksheets("Addresses").Range("A2").CurrentRegion
Set r1 = r.Offset(r.Rows.Count, 0)
r1.Cells(1).Value = txtFirstName.Value
r1.Cells(2).Value = txtLastName.Value
r1.Cells(3).Value = txtAddress.Value
r1.Cells(4).Value = txtCity.Value
r1.Cells(5).Value = cmbStates.Value
r1.Cells(6).Value = txtZip.Value
End Sub