Application-defined or object-defined error

S

Sharon

Basically I want to fill cells in workbook PeriodXX with
cells from workbook 202forecast.
First I get a number from the user, then I use that to
pick which sheet the data comes from:

Sub UpdatePeriodXX()
PeriodNum = Application.InputBox("Please Enter The Period
Number")
Worksheets("WEEKONE").Range("PERIOD").Value = PeriodNum

Select Case PeriodNum
Case 1
UpdateWeek1
Case 2
UpdateWeek2
Case Else
Exit Sub
End Select
End Sub 'it gets thru this ok

Sub UpdateWeek1()
Workbooks("PeriodXXInProcess.xls").Worksheets
("WEEKONE").Range("Salary").Value = Workbooks
("202forecast.xls").Worksheets(PeriodNum).Range
("Salary").Value 'this is the line that errors out
End Sub

"Salary" is a range of cells.
I named a range in both workbooks as Salary. I want to
fill one range with the values from the other one. Is
that not possible? Or is the syntax just wrong?

Thank you -
Sharon
 
T

Tom Ogilvy

I always use the names collection in a situation like this

Sub UpdateWeek1()
Workbooks("PeriodXXInProcess.xls"). _
Worksheets("WEEKONE").Names("Salary"). _
RefersToRange.Value = _
Workbooks("202forecast.xls"). _
Worksheets(periodNum).Names("Salary"). _
RefersToRange.Value
End Sub
 
S

Sharon

I'm just learning about collections, so I'll have to read
up on that. I tried the code and I get the same error.
But thank you -
Maybe I'll just need to do a copy and paste.
Sharon
 

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