Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
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 June 9th, 2004, 11:37 AM
kud kud is offline
Registered User
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code to populate multiple sheet into workbook

Populate multiple Sheets

Sub CreateWorksheet()
Dim var As Variant
Dim dept As String
Dim lX As Long
Dim iCols As Integer

iCols = ActiveSheet.UsedRange.Columns.Count
Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Key2:=Range("C1") _
    , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
    False, Orientation:=xlTopToBottom

Range(Cells(1, 2), Cells(ActiveSheet.UsedRange.Rows.Count, 2)).Select

For Each var In Selection
  If Trim$(var.Value) = "" Then Exit For
  If dept <> var.Value Then
    ActiveSheet.Name = var.Value
    dept = var.Value
    lX = 0
  End If
  lX = lX + 1
  Sheets("Sheet1").Range(Cells(var.Row, 1), Cells(var.Row, iCols)).Copy _
    Destination:=Sheets(dept).Cells(lX, 1)
' ActiveSheet.Cells(lX, 1).Value = Sheets("Sheet1").Range(Cells(var.Row, 2), Cells(var.Row, iCols)).Value
Next var
End Sub

Delete mulitple sheets
Sub DeleteSheets()
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In Worksheets
'If ws.Name <> "Sheet1" And ws.Name <> "Sheet2" Then ws.Delete
If ws.Name <> "Sheet1" Then ws.Delete
Application.DisplayAlerts = True
End Sub

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Workbook,Copy Sheet,Move Sheet, Close/Save ptrussell2009 Excel VBA 0 June 13th, 2008 02:28 PM
OptionButtons as workbook sheet selector frankjuel Excel VBA 8 February 27th, 2007 05:32 PM
Loading from multiple sheets on another workbook luxcs Excel VBA 0 March 25th, 2004 03:00 PM
Can't Populate Multiple Dropdown Lists with DSO nick8245 Javascript 4 September 24th, 2003 08:55 AM

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