Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2009, 12:10 PM
Authorized User
 
Join Date: Feb 2009
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default Add new worksheet

Hi

I looking for help with VBA code to add a new worksheet base on criterion that in range a3 to down, I needs the data from range b3 to m, filter the COL C that what's the criterion to range A3 to down then copy veritable range from range “B3 to M “then paste on new worksheet range A3 with sheets named with the criteria,

Can u help me the code
I highly appreciate
Thanks
 
Old July 10th, 2009, 09:35 PM
Authorized User
 
Join Date: Feb 2009
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by ks1102 View Post
Hi

I looking for help with VBA code to add a new worksheet base on criterion that in range a3 to down, I needs the data from range b3 to m, filter the COL C that what's the criterion to range A3 to down then copy veritable range from range “B3 to M “then paste on new worksheet range A3 with sheets named with the criteria,

Can u help me the code
I highly appreciate
Thanks

please help me ,,,,,thanks
 
Old July 10th, 2009, 10:12 PM
Authorized User
 
Join Date: Nov 2007
Posts: 48
Thanks: 0
Thanked 4 Times in 4 Posts
Default

ks1102,

Try:

Excel Explosion 3.0 (free addin) at:
http://www.datapigtechnologies.com/freeware.htm

View the demo.
__________________
stanleydgromjr

Windows 8.1, Excel 2007.
 
Old July 10th, 2009, 10:38 PM
Authorized User
 
Join Date: Feb 2009
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks stanleydgromjr

May be the unclear posted .

To simply what have I wanted,

I have the years summary that’s around 25000 rows down COL inclusive A to G with the criterion Start from C2, can Automatically to have autofilter base the criterion copy rows to a new work sheet past at “A1” with sheet’s name = the what’s the criteria ?


may i have some one help the code
 
Old July 11th, 2009, 03:00 PM
Authorized User
 
Join Date: Nov 2007
Posts: 48
Thanks: 0
Thanked 4 Times in 4 Posts
Default

ks1102,

I am assuming that in the active sheet your titles are in row 2, and your data begins in row 3.


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Adding the Macro
1. Copy the below macro, by highlighting the macro code and pressing the keys CTRL+C
2. Open your workbook
3. Press the keys ALT+F11 to open the Visual Basic Editor
4. Press the keys ALT+I to activate the Insert menu
5. Press M to insert a Standard Module
6. Paste the code by pressing the keys CTRL+V
7. Press the keys ALT+Q to exit the Editor, and return to Excel.


Code:
 
Option Explicit
Sub CopyRows()
Dim wsMain As Worksheet, wsWork As Worksheet, wsNew As Worksheet
Dim LR As Long, LRW As Long, LRN As Long, a As Long
Application.ScreenUpdating = False
Set wsMain = ActiveSheet
LR = wsMain.Range("C" & Rows.Count).End(xlUp).Row
Set wsWork = Worksheets.Add
wsMain.Range("C2:C" & LR).Copy wsWork.Range("A1")
With wsWork
  LRW = .Range("A" & Rows.Count).End(xlUp).Row
  .Range("A1:A" & LRW).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wsWork.Range("B1"), Unique:=True
  Range("A1").EntireColumn.Delete
  Range("A1").EntireRow.Delete
  LRW = .Range("A" & Rows.Count).End(xlUp).Row
End With
With wsMain
  For a = 1 To LRW Step 1
    On Error Resume Next
    Sheets(wsWork.Range("A" & a).Value).Select
    If Err Then Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = wsWork.Range("A" & a).Value
    On Error GoTo 0
    Set wsNew = ActiveSheet
    LRN = wsNew.Range("C" & Rows.Count).End(xlUp).Row
    With .Range("B2:M" & LR)
      .AutoFilter
      .AutoFilter Field:=2, Criteria1:=wsWork.Range("A" & a).Value, Operator:=xlAnd
      .Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy wsNew.Range("A" & LRN + 1)
      .AutoFilter
    End With
  Next a
End With
Application.DisplayAlerts = False
wsWork.Delete
Application.DisplayAlerts = True
wsMain.Select
Application.ScreenUpdating = True
End Sub

Then run the "CopyRows" macro.

Each time you run the macro, the data will be coped to the respective sheets.


Have a great day,
Stan
__________________
stanleydgromjr

Windows 8.1, Excel 2007.

Last edited by stanleydgromjr; July 11th, 2009 at 03:21 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
New workSheet adding ks1102 Excel VBA 2 March 10th, 2009 07:29 AM
Email Worksheet alannoble26 Excel VBA 2 November 7th, 2005 10:33 AM
Send Worksheet alannoble26 Excel VBA 3 November 2nd, 2005 01:04 PM
Setting Worksheet name marcusfromsweden XSLT 0 September 19th, 2005 11:50 AM
Creating a function to add a new worksheet edcaru Excel VBA 2 August 16th, 2004 01:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.