LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Passing a Variable to a Macro


Iam,

Is there any way to loop this macro so it keeps feeding in variables from a
range in the document until there are no more? The rest of this macro takes
the filtered list and copies to a new sheet. This allows a master list of
sales opportunity to be broekn out and formatted for each territory...


Of course - you should have asked for that up front.

The code below is written on the assumption that you have no completely blank rows or columns in
your data set, set to export based on column BY....

HTH,
Bernie
MS Excel MVP


Sub ExportSheetsFromDatabase()
'Based on the value in the 77th column
Dim myCell As Range
Dim mySht As Worksheet
Dim myName As String
Dim myArea As Range
Dim myCol As Integer

'ActiveSheet.Range("$A$5:$CW$355").AutoFilter Field:=77
'Export based on values in column BY ( the 77th column of A:CW)

myCol = 77

Set myArea = ActiveSheet.Range("$A$5:$CW$" & Cells(Rows.Count, 1).End(xlUp).Row)
Set myArea = myArea(2, myCol).Resize(myArea.Rows.Count - 1, 1)

For Each myCell In myArea
On Error GoTo NoSheet
myName = Worksheets(myCell.Value).Name
GoTo SheetExists:
NoSheet:
Set mySht = Worksheets.Add
mySht.Name = myCell.Value
With myCell.CurrentRegion
.AutoFilter Field:=myCol, Criteria1:=myCell.Value
.SpecialCells(xlCellTypeVisible).Copy _
mySht.Range("A1")
mySht.Cells.EntireColumn.AutoFit
.AutoFilter
End With
Resume
SheetExists:
Next myCell
End Sub

"IAM" wrote in message
...
Wow. That was super easy. Of course it opens up many more possibilities in my
mind.

I there any way to give a pick list from a named range in the excel sheet
for a variable in the criteria for this macro?

OR

Is there any way to loop this macro so it keeps feeding in variables from a
range in the document until there are no more? The rest of this macro takes
the filtered list and copies to a new sheet. This allows a master list of
sales opportunity to be broekn out and formatted for each territory...

Iam





 
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
Passing variable to Access Job Excel Programming 4 July 6th 05 03:52 PM
Passing variable to VarType of other Variable ExcelMonkey[_190_] Excel Programming 3 February 22nd 05 01:38 PM
Passing variable from one sub to another Medemper Excel Programming 0 February 26th 04 10:23 PM
Passing a value to a variable from Userform Neal Steiner Excel Programming 1 July 18th 03 09:12 PM
Question: Macro overloading, passing variable number of arguments Frederik Romanov Excel Programming 1 July 8th 03 02:51 PM


All times are GMT +1. The time now is 09:32 AM.

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"