Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Find next ID in non sort column

Hi,
I have sheet with column A the values in the column a
ss001
ss002
hh001
hh005
ss003
The values are ID. I want to find the next ID according to the prefix.
In the above example the next ID when prefix 'ss' is '22004' and when prefix
is 'hh' the next ID is 'hh006'
How can I do it in the code ? (VBA+excel) How I find the next ID?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Find next ID in non sort column

dim s as String, sNextID as string
Dim max as Long, n as String
Dim lNum as Long
max = 0
for each cell in selection
s = left(cell,2)
n = Right(cell,len(cell)-2)
if s = "ss" then
lNum = clng(n)
if lNum max then
max = lNum
end if
end if
Next
sNextID = "ss" & format(lNum+1,"000")

--
Regards,
Tom Ogilvy


"Shlomit" wrote:

Hi,
I have sheet with column A the values in the column a
ss001
ss002
hh001
hh005
ss003
The values are ID. I want to find the next ID according to the prefix.
In the above example the next ID when prefix 'ss' is '22004' and when prefix
is 'hh' the next ID is 'hh006'
How can I do it in the code ? (VBA+excel) How I find the next ID?

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
How to sort without including column headings in sort OPDvolunteer Excel Discussion (Misc queries) 4 March 11th 09 04:08 PM
data, sort option is grayed. how to sort on a column? Steve Richter Excel Discussion (Misc queries) 1 September 25th 07 03:25 PM
how do I find and sort unique values from a column spreadsheet monkey Excel Worksheet Functions 1 March 28th 07 08:39 AM
Can Excel find & sort one item in all the cells in a column? AHSinVT New Users to Excel 3 January 22nd 06 10:24 PM
How can I find and sort specific data within a column? bpreas - ExcelForums.com Excel Discussion (Misc queries) 3 August 2nd 05 07:11 PM


All times are GMT +1. The time now is 11:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"