Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Runtime error "1004" on this code, help pls

I have this code:
Private Sub RollUP_Click()


Dim newRng As Range
Dim newWs As Worksheet


Set newWs = Worksheets("ROLLUP")
Set newRng = newWs.Range("B:B")

For Each Sh In ActiveWorkbook.Worksheets
If Sh.Name < newWs.Name Then

Sh.Range("G:G").Copy
newRng.PasteSpecial xlPasteValues
newRng.PasteSpecial xlPasteFormats

Sh.Range("lblWTotal").Value = Sh.Name
Set newRng = newRng.Offset(0, 1)
End If
Next

Application.ScreenUpdating = False
Worksheets("ROLLUP").Columns("B").Hidden = True
Application.ScreenUpdating = True

End Sub

--------
and each time I run it, I get the 1004 error message on this code
Sh.Range("lblWTotal").Value = Sh.Name

What I'm trying to accomplish is to change the value of a merged cell
named "lblWTotal" from each worksheet to the name of the worksheet
(ie. 205, 206, 207, 208, etc).

Thanks for your help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Runtime error "1004" on this code, help pls

I suspecty that you do not have a range named lblWTotal locally defined on
each sheet in your workbook. give this code a try...

Private Sub RollUP_Click()


Dim newRng As Range
Dim newWs As Worksheet
Dim rng as Range


Set newWs = Worksheets("ROLLUP")
Set newRng = newWs.Range("B:B")

For Each Sh In ActiveWorkbook.Worksheets
If Sh.Name < newWs.Name Then

Sh.Range("G:G").Copy
newRng.PasteSpecial xlPasteValues
newRng.PasteSpecial xlPasteFormats

set rng = nothing
On error resume next
set rng = Sh.Range("lblWTotal")
On error goto 0
if rng is nothing then
msgbox "Sheet " & sh.name & " does not contain lblWTotal"
else
Sh.Range("lblWTotal").Value = Sh.Name
end if
Set newRng = newRng.Offset(0, 1)
End If
Next

Application.ScreenUpdating = False
Worksheets("ROLLUP").Columns("B").Hidden = True
Application.ScreenUpdating = True

End Sub


--
HTH...

Jim Thomlinson


" wrote:

I have this code:
Private Sub RollUP_Click()


Dim newRng As Range
Dim newWs As Worksheet


Set newWs = Worksheets("ROLLUP")
Set newRng = newWs.Range("B:B")

For Each Sh In ActiveWorkbook.Worksheets
If Sh.Name < newWs.Name Then

Sh.Range("G:G").Copy
newRng.PasteSpecial xlPasteValues
newRng.PasteSpecial xlPasteFormats

Sh.Range("lblWTotal").Value = Sh.Name
Set newRng = newRng.Offset(0, 1)
End If
Next

Application.ScreenUpdating = False
Worksheets("ROLLUP").Columns("B").Hidden = True
Application.ScreenUpdating = True

End Sub

--------
and each time I run it, I get the 1004 error message on this code
Sh.Range("lblWTotal").Value = Sh.Name

What I'm trying to accomplish is to change the value of a merged cell
named "lblWTotal" from each worksheet to the name of the worksheet
(ie. 205, 206, 207, 208, etc).

Thanks for your help.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Runtime error "1004" on this code, help pls

Thanks Jim. I now realized what went wrong. You were right, not all
my worksheets contain "lblWTotal" and I forgot to exclude them in the
If statement.


Thanks for the fast response. Now I can move on to the next
problem. :)


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
runtime error code 1004 Karen Excel Worksheet Functions 1 May 13th 10 12:21 AM
Hiding Rows Error - "Runtime Error 1004 - Unable to set the hidden property of the range class" Punsterr Excel Programming 2 April 9th 07 05:32 PM
Error Message "Runtime error '13' Type mismatch" Chris Excel Programming 4 November 15th 06 05:21 PM
Runtime Error "1004" Select Method of Range Class Failed Stephen[_7_] Excel Programming 4 April 10th 04 06:28 AM
RunTime Error "1004" QueryTable is Invalid Devendra[_3_] Excel Programming 1 January 21st 04 11:01 AM


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

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"