method 'Name' of object '_Worksheet' failed

gletuckin

New Member
Joined
Apr 20, 2011
Messages
1
Hi guys, please help me

i need some for my macro, there's error message on line wsNew.Name = c.Value n the message is method 'Name' of object '_Worksheet' failed ..what the cause of problem..i'v confused....this is the macro that i'v made :

Option Explicit

Sub Proses()

Dim ws1 As Worksheet
Dim wsNew As Worksheet
Dim rng As Range
Dim r As Integer
Dim c As Range
Set ws1 = Sheets("Reminder")
Set rng = Range("A1:U199")

'extract a list of Sales Reps
ws1.Columns("D:D").Copy _
Destination:=Range("Y1")
ws1.Columns("Y:Y").AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=Range("V5"), Unique:=True
r = Cells(Rows.Count, "V").End(xlUp).Row

'set up Criteria Area
Range("Y5").Value = Range("D5").Value

For Each c In Range("V6:V" & r)
'add the rep name to the criteria area
ws1.Range("Y6").Value = c.Value
'add new sheet (if required)
'and run advanced filter
If WksExists(c.Value) Then
Sheets(c.Value).Cell
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Reminder").Range("Y1:Y2"), _
CopyToRange:=Sheets(c.Value).Range("A5"), _
Unique:=False
Else
Set wsNew = Sheets.Add
wsNew.Move After:=Worksheets(Worksheets.Count)
wsNew.Name = c.Value
method 'Name' of object '_Worksheet' failed
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Reminder").Range("Y1:Y2"), _
CopyToRange:=wsNew.Range("A5"), _
Unique:=False
End If
Next
ws1.Select
ws1.Columns("V:Y").Delete




Dim cari1, cari2, cari3, cari4
Dim baris As Integer
Dim tulis As Boolean
Dim I, J, K As Integer
Dim Col(20) As String

J = 1
baris = 7

For I = 1 To 20
Col(I) = ""
Next I

Sheets("Reminder").Select


For I = 4 To 1000000
If Sheets("n-6").Cells(I, "E") = "" Then Exit For

tulis = False

If (Sheets("n-6").Cells(I, "P") >= 2010) Then

Set cari1 = Sheets("n-1").Columns("E").Find(Sheets("n-6").Cells(I, "E"), LookIn:=xlValues, lookAt:=xlWhole)
Set cari2 = Sheets("n").Columns("E").Find(Sheets("n-6").Cells(I, "E"), LookIn:=xlValues, lookAt:=xlWhole)
If cari1 Is Nothing And cari2 Is Nothing Then
tulis = True
End If

If tulis = True Then
Set cari3 = Sheets("Reminder").Columns("E").Find(Sheets("n-6").Cells(I, "E"), LookIn:=xlValues, lookAt:=xlWhole)

If cari3 Is Nothing Then
Sheets("Reminder").Cells(baris, "A") = baris - 5
Sheets("Reminder").Cells(baris, "B") = Sheets("n-6").Cells(I, "B") 'nama
Sheets("Reminder").Cells(baris, "C") = Sheets("n-6").Cells(I, "C") 'alamat
Sheets("Reminder").Cells(baris, "D") = Sheets("n-6").Cells(I, "D") 'sa
Sheets("Reminder").Cells(baris, "E") = Sheets("n-6").Cells(I, "E") 'equip
Sheets("Reminder").Cells(baris, "F") = Sheets("n-6").Cells(I, "F") 'noPolisi
Sheets("Reminder").Cells(baris, "G") = Sheets("n-6").Cells(I, "G") '
Sheets("Reminder").Cells(baris, "H") = Sheets("n-6").Cells(I, "H") 'home
Sheets("Reminder").Cells(baris, "I") = Sheets("n-6").Cells(I, "I") 'office
Sheets("Reminder").Cells(baris, "J") = Sheets("n-6").Cells(I, "J") 'mobile
Sheets("Reminder").Cells(baris, "K") = Sheets("n-6").Cells(I, "K") '
Sheets("Reminder").Cells(baris, "L") = Sheets("n-6").Cells(I, "L") 'tipe
Sheets("Reminder").Cells(baris, "M") = Sheets("n-6").Cells(I, "M") 'tgl srv
Sheets("Reminder").Cells(baris, "N") = Sheets("n-6").Cells(I, "N") 'tgl selesai
Sheets("Reminder").Cells(baris, "O") = Sheets("n-6").Cells(I, "O") '
Sheets("Reminder").Cells(baris, "P") = Sheets("n-6").Cells(I, "P") 'tahun prod
Sheets("Reminder").Cells(baris, "Q") = Sheets("n-6").Cells(I, "Q") 'km
Sheets("Reminder").Cells(baris, "R") = Sheets("n-6").Cells(I, "R") 'tgl.deliv
Sheets("Reminder").Cells(baris, "S") = Sheets("n-6").Cells(I, "S") '
Sheets("Reminder").Cells(baris, "T") = Sheets("n-6").Cells(I, "T") 'job type
Sheets("Reminder").Cells(baris, "U") = "10K"
Sheets("Reminder").Cells(baris, "A").Select

baris = baris + 1
End If
End If
End If
Next I
Sheets("Reminder").Select
Sheets("Reminder").Cells(6, "A").Select

End Sub
Function WksExists(wksName As String) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function

Any help with solving this annoying error would really be appreciated!
Thanks in advance, and sorry for the long post!
Gle
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Set wsNew = Sheets.Add
wsNew.Move After:=Worksheets(Worksheets.Count)
wsNew.Name = c.Value method 'Name' of object '_Worksheet' failed

I have had similar issues naming new worksheets and have gone to using...

ActiveSheet.Name = c.Value

I have also had issues with c.Value not being a string and having to convert to a string before you can use as a ws name.

Just a thought. Neither has been tested.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top