Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Make Sheets.(Range 1) = Sheets.(Range 2)

I am getting an Error on the line indicated below. FacePlastic_BOM is
declared and calculated in another Sub in the UserForm. For now
FacePlastic_BOM = 160.

Dim LastRow As Single

Sheets("BOM & Labor").Unprotect "AdTech"

LastRow = Sheets("BOM & Labor").Cells(Rows.Count, "A").End(xlUp).Row + 1

'plastic material
'ERROR == Sheets("BOM & Labor").Range(Cells(LastRow, "A"),
Cells(LastRow, "D")) = _
Sheets("Parts List").Range(Cells(FacePlastic_BOM, "A"),
Cells(FacePlastic_BOM, "D"))


Thanks in Advance,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Make Sheets.(Range 1) = Sheets.(Range 2)

The problem is that in the line

Sheets("BOM & Labor").Range(Cells(LastRow, "A"), Cells(LastRow, "D")) = _
Sheets("Parts List").Range(Cells(FacePlastic_BOM, "A"),
Cells(FacePlastic_BOM, "D"))

the Cells reference refers to the ActiveSheet (since no sheet is specified),
not the Sheets("BOM & Labor") worksheet. Use a With statement as follows:

With Sheets("BOM & Labor")
..Range(Cells(LastRow, "A"), .Cells(LastRow, "D")) = _
Sheets("Parts List").Range(Cells(.FacePlastic_BOM, "A"),
Cells(.FacePlastic_BOM, "D"))
End With

Pay close attention to the '.' characters before Cells. If there is a period
before the word 'Cells', it will refer to the sheet specified in the With
statement. Absent a period, it will refer to the ActiveSheet.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





"RyanH" wrote in message
...
I am getting an Error on the line indicated below. FacePlastic_BOM is
declared and calculated in another Sub in the UserForm. For now
FacePlastic_BOM = 160.

Dim LastRow As Single

Sheets("BOM & Labor").Unprotect "AdTech"

LastRow = Sheets("BOM & Labor").Cells(Rows.Count, "A").End(xlUp).Row + 1

'plastic material
'ERROR == Sheets("BOM & Labor").Range(Cells(LastRow, "A"),
Cells(LastRow, "D")) = _
Sheets("Parts List").Range(Cells(FacePlastic_BOM, "A"),
Cells(FacePlastic_BOM, "D"))


Thanks in Advance,
Ryan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Make Sheets.(Range 1) = Sheets.(Range 2)

Thanks for the reply. I copied your code and I am getting an Application
Error. The FacePlastic_BOM variable references a row number in Sheets("Parts
List"). Should it have a "." in front of it?

I tried to rewrite it this way. Now I am not getting an error, but I do not
see the text in Sheets("BOM & Labor") Range. Any ideas?

Sheets("BOM & Labor").Range("A" & LastRow & ":D" & LastRow) = _
Sheets("Parts List").Range("A" & FacePlastic_BOM & ":D" & FacePlastic_BOM)

Thanks,
Ryan


"Chip Pearson" wrote:

The problem is that in the line

Sheets("BOM & Labor").Range(Cells(LastRow, "A"), Cells(LastRow, "D")) = _
Sheets("Parts List").Range(Cells(FacePlastic_BOM, "A"),
Cells(FacePlastic_BOM, "D"))

the Cells reference refers to the ActiveSheet (since no sheet is specified),
not the Sheets("BOM & Labor") worksheet. Use a With statement as follows:

With Sheets("BOM & Labor")
.Range(Cells(LastRow, "A"), .Cells(LastRow, "D")) = _
Sheets("Parts List").Range(Cells(.FacePlastic_BOM, "A"),
Cells(.FacePlastic_BOM, "D"))
End With

Pay close attention to the '.' characters before Cells. If there is a period
before the word 'Cells', it will refer to the sheet specified in the With
statement. Absent a period, it will refer to the ActiveSheet.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





"RyanH" wrote in message
...
I am getting an Error on the line indicated below. FacePlastic_BOM is
declared and calculated in another Sub in the UserForm. For now
FacePlastic_BOM = 160.

Dim LastRow As Single

Sheets("BOM & Labor").Unprotect "AdTech"

LastRow = Sheets("BOM & Labor").Cells(Rows.Count, "A").End(xlUp).Row + 1

'plastic material
'ERROR == Sheets("BOM & Labor").Range(Cells(LastRow, "A"),
Cells(LastRow, "D")) = _
Sheets("Parts List").Range(Cells(FacePlastic_BOM, "A"),
Cells(FacePlastic_BOM, "D"))


Thanks in Advance,
Ryan


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
same range name in different sheets Gilbert DE CEULAER Excel Discussion (Misc queries) 2 November 26th 08 01:39 PM
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Worksheet Functions 6 March 29th 06 12:43 PM
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Programming 6 March 29th 06 12:43 PM
range of data from different sheets SteW Charts and Charting in Excel 2 June 26th 05 07:31 PM
sheets.range and adding cells that are out of the range Phillips Excel Programming 1 November 18th 03 09:27 PM


All times are GMT +1. The time now is 10:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"