LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Copying data & creating new worksheets - error

I'm trying to create new worksheets based on a column in my active
worksheet. I've copied and altered some code from ron debruin's
webpage. This is part of a much longer module that defined the range
previously. I keep getting caught up in this one area and get an error
that says: "Object variable or With block variable not set" Yes, I'm
clueless and really don't know what I am doing but could use some
help/advice. Thanks.


Dim CalcMode As Long
Dim ws1 As Worksheet
Dim WSNew As Worksheet
Dim cell As Range
Dim Lrow As Long

'Tip : Use a Dynamic range name,
http://www.contextures.com/xlNames01.html#Dynamic
'or a fixed range like Range("A1:H1200")
Set rng = ws1.Range("A1", ("A" & NoAccounts)).Product '<<< Change

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'THIS IS WHERE THE ERROR IS OCCURING
With ws1
==========================rng.Columns(1).Advanced Filter _
==========================Action:=xlFilterCopy, _
==========================CopyToRange:=.Range("CR 1"),
Unique:=True[b]
'This example filter on the first column in the range (change
this if needed)
'You see that the last two columns of the worksheet are used to
make a Unique list
'and add the CriteriaRange.(you can't use this macro if you use
the columns)


Lrow = .Cells(Rows.Count, "CR").End(xlUp).row
.Range("CQ1").Value = .Range("CR1").Value

For Each cell In .Range("CR2:CR" & Lrow)
.Range("CQ2").Value = cell.Value
Set WSNew = Sheets.Add
On Error Resume Next
WSNew.Name = cell.Value
If Err.Number 0 Then
MsgBox "Change the name of : " & WSNew.Name & "
manually"
Err.Clear
End If
On Error GoTo 0
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("J1:J2"), _
CopyToRange:=WSNew.Range("A1"), _
Unique:=False
WSNew.Columns.AutoFit
Next
.Columns("J:K").Clear
End With

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

 
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
copying data between worksheets SURGEON1971 Excel Discussion (Misc queries) 2 March 26th 09 08:50 AM
I get an error message while copying worksheets between workbooks CRACARCONSTRUCTION Excel Discussion (Misc queries) 1 February 16th 09 09:56 PM
Copying data across worksheets Maki Excel Discussion (Misc queries) 2 September 15th 08 02:40 PM
Copying data across different worksheets Nic M Excel Discussion (Misc queries) 4 May 8th 06 09:30 PM
Macro programming for Creating New Sheets and Copying Data Addy Excel Programming 1 May 1st 06 05:04 PM


All times are GMT +1. The time now is 11:55 PM.

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

About Us

"It's about Microsoft Excel"