Thread
:
Worksheet name with space problem
View Single Post
#
8
Posted to microsoft.public.excel.programming
Dave Peterson
external usenet poster
Posts: 35,218
Worksheet name with space problem
The code I used deleted worksheets with those test names--if they existed. I
wanted to make sure that if you ran the code twice, it would not end in an error
when the renaming of the new worksheets took place.
No you shouldn't have to rename those worksheets that have spaces in their
names. You may want to try that suggested code in a new workbook to see if
works for you.
Since you haven't posted any real details, I'm guessing that the error is caused
by an error in your code--not because of the space in the worksheet name.
wrote:
I don't why you are deleting the worksheets and then adding them.
I have a workbook that contains the code and worksheets for retrieving the
data.
I open up a workbook that contains a worksheet with rows and columns of data
of which one column I want to extract into the first workbook. If the data
worksheet's name has a space in it the autofilter code errors.
Right now I have added code to replace the spaces with the infamous _ but
you shouldn't have to do that unless it is a geniune bug and supposedly your
code works.
This is my code
Set wsEx = ThisWorkbook.Worksheets("ExtractData")
Set wsData = ActiveSheet 'activesheet name could be My Worksheet
wsData.Range("DataCol").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=wsEx .Range("LDExCrit"), _
CopyToRange:=wsEx .Range("ExtractCol"), Unique:=True
I notice you don't have the CriteriaRange set but that shouldn't affect it.
You also are setting the worksheet variables to the initial add worksheet
code instead of the name of the worksheet such or activesheet which could
make a difference.
I am using named ranges but that shouldn't matter either.
Steve
"Dave Peterson" wrote in message
...
Does excel crash when you create a small test workbook.
This didn't crash xl2003 for me:
Option Explicit
Sub testme01()
Dim wks1 As Worksheet
Dim wks2 As Worksheet
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("name with space1").Delete
Worksheets("name with space2").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Set wks1 = Worksheets.Add
With wks1
.Name = "name with space1"
.Range("a1").Value = "header"
.Range("a2:a10").Formula = "=""A""&mod(row(),3)"
End With
Set wks2 = Worksheets.Add
wks2.Name = "Name with space2"
wks1.Range("a1:A10").AdvancedFilter _
action:=xlFilterCopy, _
copytorange:=wks2.Range("a1"), _
unique:=True
End Sub
wrote:
Doing an advanced filter on a worksheet with a space in the worksheet
name
causes it to crash even if using a variable such as
ws.range(somerange).advancedfilter.
Anyone know what causes it or work around?
Thanks
--
Dave Peterson
--
Dave Peterson
Reply With Quote
Dave Peterson
View Public Profile
Find all posts by Dave Peterson