Range error

G

Guest

I am wanting this to run while on one worksheet while information is on
another worksheet.

Form works until it gets to the
'fill down formula
where is says object failed_worksheet

I could use some help. Thank you!

Private Sub cmdEmpOK_Click()
Dim lastrow As Long
Dim ws As Worksheet
Set ws = Worksheets("Database")

'Finds the last row in the range and drops down 1 below
lastrow = Worksheets("Database").Range("database").End(xlDown).Row + 1

'Fills the cells with values from text boxes
ws.Cells(lastrow, 1).Value = txtEmpName.Value
ws.Cells(lastrow, 2).Value = txtEmpPosition.Value
ws.Cells(lastrow, 3).Value = Calendar1.Value
ws.Cells(lastrow, 4).Value = txtSalary.Value

'Fills down the formula

Worksheets("Database").Range("e2", Range("a2").End(xlDown)).Offset(0,
4).FillDown

'Worksheets("GwrStmts").Range("GwrStmt").Copy ws.Cells(iRow, 1)
'Clears form
Call UserForm_Initialize
End Sub
 
G

Guest

try this modification. I think the problem is with Range("a2" should of been
With Worksheets("Database").Range("a2")

Using the WITH makes it easier to code.


With Worksheets("Database")
.Range("e2", .Range("a2").End(xlDown)). _
Offset(0, 4).FillDown
End With
 

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