ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Range error (https://www.excelbanter.com/excel-discussion-misc-queries/165067-range-error.html)

Jennifer

Range error
 
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(xlDow n).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
--
Thank you,

Jennifer

joel

Range error
 
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

"Jennifer" wrote:

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(xlDow n).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
--
Thank you,

Jennifer



All times are GMT +1. The time now is 09:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com