Importing data and sorting into different worksheets

  • Thread starter Thread starter gilesjp
  • Start date Start date
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
 
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
 
Back
Top