Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Finding MAX Value of Part of Cell Contents

I have a list of values in :
Sheet8.Range("E:E")
that are formatted as:
ST 1234 ' IE "ST_1234" where "_" = Space

I want to place the Maximum Numerical Value +1 into a Textbox on a Userform,
But to date i have yet worked out how to manage it?

Any One assist me ?
Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Finding MAX Value of Part of Cell Contents

Corey:

This function will find the value for you. You then have to add one to it
and put it in the text box.

Function findmax() As Long
Const iColumn As Integer = 5 ' column to use
Const iCharsToIgnore As Integer = 3 ' chars to ignore at start
Dim ws As Worksheet
Dim lRowStart As Long, lRowEnd As Long
Dim rCell As Range
Dim lMax As Long ' from spec no -ve values and only integers lmax
default 0 ok
Dim lCur As Long ' current number
' set sheet to use
Set ws = ActiveSheet

'find first and last rows
lRowStart = ws.UsedRange.Row
lRowEnd = ws.UsedRange.Rows.Count + lRowStart - 1
On Error Resume Next ' catch errors
For Each rCell In Range(Cells(lRowStart, iColumn), Cells(lRowEnd,
iColumn))
If rCell < "" Then
' on error uses last value ok may want better error checking
lCur = Right(rCell.Value, Len(rCell.Value) - iCharsToIgnore)
If lCur lMax Then lMax = lCur
End If
Next rCell
findmax = lMax
End Function

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Corey" wrote:

I have a list of values in :
Sheet8.Range("E:E")
that are formatted as:
ST 1234 ' IE "ST_1234" where "_" = Space

I want to place the Maximum Numerical Value +1 into a Textbox on a Userform,
But to date i have yet worked out how to manage it?

Any One assist me ?
Corey....



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Finding MAX Value of Part of Cell Contents

Thank you for the code Martin,
It works great, but i then discovered i need to use it across more than just
1 Column.

Is there a simply way to have it do the following:

Function findmax() As Long
Const iColumn As Integer = 5 '<================= Look in Columns 5 & 7 &
9 & 11 INSTEAD of just 5???
Const iCharsToIgnore As Integer = 3 ' chars to ignore at start
Dim ws As Worksheet
Dim lRowStart As Long, lRowEnd As Long
Dim rCell As Range
Dim lMax As Long ' from spec no -ve values and only integers lmax
default 0 ok
Dim lCur As Long ' current number
Sheet8.Select ' set sheet to use
Set ws = ActiveSheet
'find first and last rows
lRowStart = ws.UsedRange.Row
lRowEnd = ws.UsedRange.Rows.Count + lRowStart - 1
On Error Resume Next ' catch errors
For Each rCell In Range(Cells(lRowStart, iColumn), Cells(lRowEnd,
iColumn))
If rCell < "" Then
' on error uses last value ok may want better error checking
lCur = Right(rCell.Value, Len(rCell.Value) - iCharsToIgnore)
If lCur lMax Then lMax = lCur
End If
Next rCell
findmax = lMax
UserForm5.TextBox7.Value = "ST " & lMax + 1
End Function




Corey....
"Martin Fishlock" wrote in message
...
Corey:

This function will find the value for you. You then have to add one to it
and put it in the text box.

Function findmax() As Long
Const iColumn As Integer = 5 ' column to use
Const iCharsToIgnore As Integer = 3 ' chars to ignore at start
Dim ws As Worksheet
Dim lRowStart As Long, lRowEnd As Long
Dim rCell As Range
Dim lMax As Long ' from spec no -ve values and only integers lmax
default 0 ok
Dim lCur As Long ' current number
' set sheet to use
Set ws = ActiveSheet

'find first and last rows
lRowStart = ws.UsedRange.Row
lRowEnd = ws.UsedRange.Rows.Count + lRowStart - 1
On Error Resume Next ' catch errors
For Each rCell In Range(Cells(lRowStart, iColumn), Cells(lRowEnd,
iColumn))
If rCell < "" Then
' on error uses last value ok may want better error checking
lCur = Right(rCell.Value, Len(rCell.Value) - iCharsToIgnore)
If lCur lMax Then lMax = lCur
End If
Next rCell
findmax = lMax
End Function

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Corey" wrote:

I have a list of values in :
Sheet8.Range("E:E")
that are formatted as:
ST 1234 ' IE "ST_1234" where "_" = Space

I want to place the Maximum Numerical Value +1 into a Textbox on a
Userform,
But to date i have yet worked out how to manage it?

Any One assist me ?
Corey....





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
Looking Up Part Cell Contents Steve Excel Discussion (Misc queries) 2 April 22nd 09 05:20 PM
Combining Cell Contents (Part 2) PaolaAndrea Excel Discussion (Misc queries) 3 May 9th 08 08:10 PM
Delete part of cell contents nxqviet Excel Programming 3 December 20th 06 11:24 PM
IF statement that looks at part of the contents of a cell. Jon[_21_] Excel Programming 3 November 9th 05 04:27 PM
Can I use cell contents as part of a formula? Brian Rhodes Excel Worksheet Functions 3 June 3rd 05 05:00 PM


All times are GMT +1. The time now is 04:02 PM.

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"