#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code error

Hi all,

I am having trouble running the code below. An error keeps occurrin
with this line:

rng.Offset(1, 0).ClearContents

Any ideas....please???

Cheers!!!

Private Sub Commandbutton1_click()
CopyData Range("C13:C24"), "BASE MACHINE"
CopyData Range("C71:C85"), "CONTROL INCLUSIONS - UNIT 1"
CopyData Range("C91:C91"), "FEEDER INCLUSIONS - UNIT 1"
CopyData Range("C98:C112"), "FOLDING UNIT INCLUSIONS - UNIT 1"
CopyData Range("C142:C152"), "CONTROL INCLUSIONS - UNIT 2"
CopyData Range("C158:C168"), "FOLDING UNIT INCLUSIONS - UNIT 2"
CopyData Range("C181:C183"), "KNIFE INCLUSIONS - UNIT 2"
CopyData Range("C196:C200"), "KNIFE INCLUSIONS - UNIT 3"
End Sub
Private Sub CopyData(rngC As Range, Target As String)
Dim rng As Range, cell As Range
Dim rng1 As Range, rng2 As Range
Dim rng3 As Range
Dim nrow As Long, rw As Long
Dim Sh As Worksheet
nrow = Application.CountIf(rngC, "0")
If nrow = 0 Then Exit Sub
Set Sh = Worksheets("sheet1")
Set rng = Sh.Columns(1).Find(What:=Target, _
After:=Sh.Range("A1"), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
Set rng3 = rng
'Worksheets("quote2").Unprotect Password:="jenjen1"
rng.Offset(1, 0).ClearContents
If Application.CountA(rng3) 2 Then
Else
Set rng3 = rng.Offset(2, 0)
End If
rw = rng3.Row
rng3.Resize(nrow * 2, 1).EntireRow.Insert
For Each cell In rngC
If Not IsEmpty(cell) Then
If IsNumeric(cell) Then
If cell 0 Then
Cells(cell.Row, 1).Resize(1, 2).Copy _
Destination:=Sh.Cells(rw, 1)
rw = rw + 2
End If
End If
End If
Next
'Worksheets("quote2").Protect Password:="jenjen1"
End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Code error

Are you sure that rng is actually an object. Try

If Not rng Is Nothing Then
rng.Offset(1, 0).ClearContents
Else
Msgbox "Nothing found"
End If

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"gavmer " wrote in message
...
Hi all,

I am having trouble running the code below. An error keeps occurring
with this line:

rng.Offset(1, 0).ClearContents

Any ideas....please???

Cheers!!!

Private Sub Commandbutton1_click()
CopyData Range("C13:C24"), "BASE MACHINE"
CopyData Range("C71:C85"), "CONTROL INCLUSIONS - UNIT 1"
CopyData Range("C91:C91"), "FEEDER INCLUSIONS - UNIT 1"
CopyData Range("C98:C112"), "FOLDING UNIT INCLUSIONS - UNIT 1"
CopyData Range("C142:C152"), "CONTROL INCLUSIONS - UNIT 2"
CopyData Range("C158:C168"), "FOLDING UNIT INCLUSIONS - UNIT 2"
CopyData Range("C181:C183"), "KNIFE INCLUSIONS - UNIT 2"
CopyData Range("C196:C200"), "KNIFE INCLUSIONS - UNIT 3"
End Sub
Private Sub CopyData(rngC As Range, Target As String)
Dim rng As Range, cell As Range
Dim rng1 As Range, rng2 As Range
Dim rng3 As Range
Dim nrow As Long, rw As Long
Dim Sh As Worksheet
nrow = Application.CountIf(rngC, "0")
If nrow = 0 Then Exit Sub
Set Sh = Worksheets("sheet1")
Set rng = Sh.Columns(1).Find(What:=Target, _
After:=Sh.Range("A1"), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
Set rng3 = rng
'Worksheets("quote2").Unprotect Password:="jenjen1"
rng.Offset(1, 0).ClearContents
If Application.CountA(rng3) 2 Then
Else
Set rng3 = rng.Offset(2, 0)
End If
rw = rng3.Row
rng3.Resize(nrow * 2, 1).EntireRow.Insert
For Each cell In rngC
If Not IsEmpty(cell) Then
If IsNumeric(cell) Then
If cell 0 Then
Cells(cell.Row, 1).Resize(1, 2).Copy _
Destination:=Sh.Cells(rw, 1)
rw = rw + 2
End If
End If
End If
Next
'Worksheets("quote2").Protect Password:="jenjen1"
End Sub


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code error

hi Bob,

Thank you. Can you show me how to implement this into my existing code
Woud it be worthwhile seeing my workbook??

Cheers!!!

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code error

Hi again,

I tried what you said and yes, the error message appeared.

????????

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Code error

gavmer,
Adjust your find statement,

Set rng = Sh.Columns(1).Find(What:=Target, _
After:=Sh.Range("A1"), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If rng Is Nothing Then
Msgbox Target & "Not found"
Exit Sub
End If

"gavmer " wrote in message
...
Hi again,

I tried what you said and yes, the error message appeared.

?????????


---
Message posted from http://www.ExcelForum.com/



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
error in code des-sa[_2_] Excel Discussion (Misc queries) 5 July 3rd 08 08:09 AM
Error in Code N.F[_2_] Excel Discussion (Misc queries) 9 June 27th 07 06:48 PM
error in this code [email protected] Excel Worksheet Functions 2 December 5th 06 05:21 AM
How can I still go to the error-code after a On Error Goto? Michel[_3_] Excel Programming 2 May 4th 04 04:21 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


All times are GMT +1. The time now is 09:57 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"