Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Ayden Smith   on Feb 20 In MS Office Category.

  
Question Answered By: Joseph Evans   on Feb 20

Looks like extracting the 'numeric' part of the Acct# is what you need:

Sub FindNumericPartOfAcctNumber()

StringToEvaluate = ActiveCell.Value
StrLength = Len(StringToEvaluate)
LeftNumeric = 0

For ct = 1 To StrLength
vCharacter = Mid(StringToEvaluate, ct, 1)
Select Case vCharacter
Case 0 To 9
LeftNumeric = LeftNumeric + 1
Case Else
ct = StrLength
End Select
Next ct
NumericPartOfAcctNumber = Left(StringToEvaluate, LeftNumeric)

End Sub

This simply looks at the selected cell (active cell) & starts from left  to right
to find where the 1st non numeric position is located within the Acct# field.
The next step is to set up the loop  structure to run down the Acct# column. Then
add the decision logic (Select Case may be in order)

select case NumericPartOfAcctNumber
case 50
'place what you want to do for Acct# 50 here
case 511
'place what you want to do for Acct# 511 here
case 512
'place what you want to do for Acct# 512 here
case 531
'place what you want to do for Acct# 531 here
case else
'place what you want to do for Acct# NOT in the above list here
end select

Share: 

 

This Question has 20 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on trouble with IF/OR, Left and a simple loop Or get search suggestion and latest updates.


Tagged: