Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 9th, 2004, 11:37 AM
kud kud is offline
Registered User
Join Date: Jun 2004
Location: , , .
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

Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 09:11 AM.

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