Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default assigning numbers to companies

I need to assign companies to one of four different numbers depending on
where they fall in the alphabet, for example I need to assign a company "care
homes ltd" as 01. Any ideas on the formula?


01 A GR
02 GS SA
03 SB THEC
04 THED Z

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default assigning numbers to companies

maybe something like this:

Function GetCompanyID(strCompany As String) As String
If Left(UCase(strCompany), 1) = "A" Or Left(UCase(strCompany), 2) = "GR"
Then
GetCompanyID = "01"
End If
End Function



--

Hope that helps.

Vergel Adriano


"jamesea" wrote:

I need to assign companies to one of four different numbers depending on
where they fall in the alphabet, for example I need to assign a company "care
homes ltd" as 01. Any ideas on the formula?


01 A GR
02 GS SA
03 SB THEC
04 THED Z

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default assigning numbers to companies

ignore my answer.. don't know what I was thinking!


--

Hope that helps.

Vergel Adriano


"Vergel Adriano" wrote:

maybe something like this:

Function GetCompanyID(strCompany As String) As String
If Left(UCase(strCompany), 1) = "A" Or Left(UCase(strCompany), 2) = "GR"
Then
GetCompanyID = "01"
End If
End Function



--

Hope that helps.

Vergel Adriano


"jamesea" wrote:

I need to assign companies to one of four different numbers depending on
where they fall in the alphabet, for example I need to assign a company "care
homes ltd" as 01. Any ideas on the formula?


01 A GR
02 GS SA
03 SB THEC
04 THED Z

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default assigning numbers to companies

OK, something like this will work:

Function GetCompanyID(strCompany As String) As String
If Left(UCase(strCompany), 1) = "A" Or Left(UCase(strCompany), 2) <=
"GR" Then
GetCompanyID = "01"
End If
End Function



--

Hope that helps.

Vergel Adriano


"Vergel Adriano" wrote:

ignore my answer.. don't know what I was thinking!


--

Hope that helps.

Vergel Adriano


"Vergel Adriano" wrote:

maybe something like this:

Function GetCompanyID(strCompany As String) As String
If Left(UCase(strCompany), 1) = "A" Or Left(UCase(strCompany), 2) = "GR"
Then
GetCompanyID = "01"
End If
End Function



--

Hope that helps.

Vergel Adriano


"jamesea" wrote:

I need to assign companies to one of four different numbers depending on
where they fall in the alphabet, for example I need to assign a company "care
homes ltd" as 01. Any ideas on the formula?


01 A GR
02 GS SA
03 SB THEC
04 THED Z

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default assigning numbers to companies

Below code assumes your sheet name is "sheet1",
column A is allocated for ID numbers, column B holds your names
and columns AA to AC are available
You can run this where ever you like.

rgds

Sub makeID()

Dim rng As Range
Dim i As Range
Dim rng1 As Range
Dim str1 As String
Dim rng2 As Range
Dim str2 As String
Dim rng3 As Range
Dim str3 As String

Application.ScreenUpdating = False

Set rng1 = Application.Intersect(Worksheets("sheet1") _
.Range("aa2:aa65526"), Worksheets("sheet1").UsedRange.EntireRow)
str1 = "=Substitute(B2,"" "","""")"
Set rng2 = Application.Intersect(Worksheets("sheet1") _
.Range("ab2:ab65526"), Worksheets("sheet1").UsedRange.EntireRow)
str2 = "=MID(aa2,1,4)"
Set rng3 = Application.Intersect(Worksheets("sheet1") _
.Range("ac2:ac65526"), Worksheets("sheet1").UsedRange.EntireRow)
str3 = "=Codeit(ab2)"

rng1.Formula = str1
rng2.Formula = str2

With Worksheets("sheet1")
Set rng = .Range("ab2", .Range("ab" & Rows.Count). _
End(xlUp))
End With

For Each i In rng
Select Case Len(i.Value)
Case 1: i.Value = i.Value & "aaa"
Case 2: i.Value = i.Value & "aa"
Case 3: i.Value = i.Value & "a"
End Select
Next i

rng3.Formula = str3

With Worksheets("sheet1")
Set rng = .Range("ac2", .Range("ac" & Rows.Count). _
End(xlUp))
End With

For Each i In rng ' below numbers are your hardcoded sections
Select Case i.Value
Case 65656565 To 71829090
Worksheets("sheet1").Range("A" & i.Row) = 1
Case 71836565 To 83659090
Worksheets("sheet1").Range("A" & i.Row) = 2
Case 83666565 To 84726967
Worksheets("sheet1").Range("A" & i.Row) = 3
Case 84726968 To 90909090
Worksheets("sheet1").Range("A" & i.Row) = 4
End Select
Next i

Worksheets("sheet1").Range("aa1.ac1").EntireColumn . _
Delete

Application.ScreenUpdating = True

End Sub


Pls put below function on a standart module ( Function originally
coded by Frank Isaac )

Function CodeIt(rngName As Excel.Range) As String
Dim iX As Integer, iVal As Integer
For iX = 1 To Len(rngName)
iVal = Asc(UCase(Mid(rngName, iX, 1))) ' - 64
If iVal < 65 Or iVal 90 Then
CodeIt = CodeIt & "0"
Else
CodeIt = CodeIt & CStr(iVal)
End If
Next
End Function



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default assigning numbers to companies

For a VBA solution, maybe this. Adjust depending on how/where your company
ID data is stored. This assumes the structure as you have shown:

Public Function GetCompanyID(WhichCompany As String) As String
Dim CompIDData As Variant
Dim IDNum As Long

CompIDData = Range("rngCompIDs").Value

For IDNum = LBound(CompIDData, 1) To UBound(CompIDData, 1)
If (UCase(Left(WhichCompany, Len(CompIDData(IDNum, 2)))) =
CompIDData(IDNum, 2)) And (UCase(Left(WhichCompany, Len(CompIDData(IDNum,
3)))) <= CompIDData(IDNum, 3)) Then
GetCompanyID = CompIDData(IDNum, 1)
Exit Function
End If
Next

GetCompanyID = "#N/A"

End Function

However, you could use worksheets functions instead

NickHK

"jamesea" wrote in message
...
I need to assign companies to one of four different numbers depending on
where they fall in the alphabet, for example I need to assign a company

"care
homes ltd" as 01. Any ideas on the formula?


01 A GR
02 GS SA
03 SB THEC
04 THED Z



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default assigning numbers to companies

Thank you very much Vergel & Nick. You helped me as well.

So it is only "=GetID(B2)" on A column.

Kind regards


Public Function GetID(Company As String) As String
Select Case UCase(Company)
Case "A" To "GRZZZZZZZZZZZZZZZZZ": GetID = 1
Case "GS" To "SAZZZZZZZZZZZZZZZZ": GetID = 2
Case "SB" To "THECZZZZZZZZZZZZZZ": GetID = 3
Case "THED" To "ZZZZZZZZZZZZZZZZ": GetID = 4
End Select
End Function

Reply
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
assigning numbers to text and count them gimme_donuts[_2_] Excel Discussion (Misc queries) 4 December 31st 08 07:01 AM
Assigning a point value to a range of numbers wmb Excel Discussion (Misc queries) 2 August 7th 08 03:26 PM
Assigning a value to a set of numbers urrbie Excel Worksheet Functions 5 December 15th 06 05:10 PM
Assigning numbers to names Levi Excel Discussion (Misc queries) 1 May 4th 06 10:35 PM
assigning numbers to text entries biggybriggy Excel Discussion (Misc queries) 1 March 8th 06 04:55 AM


All times are GMT +1. The time now is 08:41 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"