Importing data and sorting into different worksheets

G

gilesjp

:confused:

I am importing data from an nds database using nds odbc drivers. I ru
the query asking for given name, surname, and user name. I need to hav
the data sorted into different worksheets. One for each geographica
location. Please help!

Thanks
 
B

Bernie Deitrick

Giles,

Once you've imported your data, select all the cells with the geographic
locations, and run the macro below.

HTH,
Bernie
MS Excel MVP

Sub SeparateDataOntoSheets()
Dim myCell As Range
Dim mySht As Worksheet
Dim myName As String

For Each myCell In Selection
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:=1, Criteria1:=myCell.Value
.SpecialCells(xlCellTypeVisible).Copy _
mySht.Range("A1")
.AutoFilter
End With
Resume
SheetExists:
Next myCell
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top