using macros to categorise a list of customers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I’m trying to use macros to separate information on different customers. I
have all the information on an excel spreadsheet and need to separate
customers into four different categories. Customers with the company name
beginning A to GR, then GS to SA, SB to THEC and THED to Z. Any ideas?
 
The following macro examines a name stored in cell A1 and puts a catagory
number in cell B1. The macro uses (Z100:Z106) as a working area. You can
pick any column of 7 unused cells. The catagory is the alphabetic
(dictionary) position:

1 - before GR
2 - after GR, before GS
3 - after GS, before SA
4 - after SA, before SB
5 - after SB, before THEC
6 - after THEC, before THED
7 - after THED

Sub katagory()

' gsnuxx

Set workarea = Range("Z100")
v = Range("A1").Value
workarea.Offset(0, 0).Value = "GR"
workarea.Offset(1, 0).Value = "GS"
workarea.Offset(2, 0).Value = "SA"
workarea.Offset(3, 0).Value = "SB"
workarea.Offset(4, 0).Value = "THEC"
workarea.Offset(5, 0).Value = "THED"
workarea.Offset(6, 0).Value = v
Set r = Range(workarea, workarea.Offset(6, 0))
r.Sort key1:=workarea

For i = 1 To 7
If workarea.Offset(i - 1, 0).Value = v Then
Range("B1").Value = i
Exit Sub
End If
Next

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

Back
Top