Next in the sequence

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

Guest

Tom

Unfortunatley the code maynot be at the bottom because we have a number of
differenct code make-ups. Is there anyway of doing the below if the code sit
in the middle of the spreadsheet i.e using an if statement...

Thanks for trying

Marcus

Tom Ogilvy said:
Assuming the last populated cell would contain that number

Dim rng as Range, nextNumber as Long
set rng = Cells(rows.count,"A").End(xlup)
nextNumber = "SAT" & clng(Right(rng,len(rng)-3)) + 1
msgbox nextNumber
Was this post helpful to you
 
Dim rng as Range, nextNumber as Long
Dim i as Long, inum as Long, maxnum as long
maxnum = 0
set rng = Cells(rows.count,"A").End(xlup)
for i = rng.row to 2 step -1
inum = clng(right(cells(i,1),len(cells(i,1)-3)))
if inum > maxnum then maxnum = inum
Next
nextNumber = "SAT" & maxnum + 1
msgbox nextNumber
 

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

Similar Threads

Loop from left to the right 5
MATCH/ LOOK UP 2
Lookup Data in external workbook 3
conditional delete 2
HOW TO PUT MSGBOX CODE IN MACRO 1
run time error 91 1
runtime 1004 error 3
Error in code 4

Back
Top