Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Figuring out MAX LEN in a given column

Hi.

I'm trying to redesign a database, originally done in Access 2003, so
exported tables to Excel to analyse existing records, and in this instance,
maximum LEN in each column that's text.
I want to program a macro which:
1. asks, via InputBox, which column to analyse;
2. starting from the row after the header, counts LEN for the record and
moves on to the next row; and
3. returns, via MsgBox, MAX value amongst all LEN counted.

I've been trying to teach myself Excel VBA programming by following John
Walkenbach's "Excel 2007 Power Programming with VBA" but I'm obviously not
"getting it" and can't even program to do COUNTA, starting with InputBox and
ending with the value shown with MsgBox.

Please help!
--
Maki @ Canberra.AU
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Figuring out MAX LEN in a given column

Try the below macro..

Sub MyMacro()
Dim lngRow As Long, varCol As Variant, intMaxLen As Integer

varCol = InputBox("Enter the column to analyse")
If IsNumeric(varCol) Then varCol = CLng(varCol)

For lngRow = 2 To Cells(Rows.Count, varCol).End(xlUp).Row
If Len(Cells(lngRow, varCol)) intMaxLen Then
intMaxLen = Len(Cells(lngRow, varCol))
End If
Next

MsgBox intMaxLen
End Sub

If you are interested in a formula try the below. Please note that this is
an array formula. You create array formulas in the same way that you create
other formulas, except you press CTRL+SHIFT+ENTER to enter the formula. If
successful in 'Formula Bar' you can notice the curly braces at both ends like
"{=<formula}"

=MAX(LEN(D2:D1000))

--
Jacob (MVP - Excel)


"Maki" wrote:

Hi.

I'm trying to redesign a database, originally done in Access 2003, so
exported tables to Excel to analyse existing records, and in this instance,
maximum LEN in each column that's text.
I want to program a macro which:
1. asks, via InputBox, which column to analyse;
2. starting from the row after the header, counts LEN for the record and
moves on to the next row; and
3. returns, via MsgBox, MAX value amongst all LEN counted.

I've been trying to teach myself Excel VBA programming by following John
Walkenbach's "Excel 2007 Power Programming with VBA" but I'm obviously not
"getting it" and can't even program to do COUNTA, starting with InputBox and
ending with the value shown with MsgBox.

Please help!
--
Maki @ Canberra.AU

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Figuring out MAX LEN in a given column

Thank you so much, Jacob. It worked treat!

I thought I needed to use Application.WorksheetFunction.Max() but didn't
know quite how to make it work.
Yours is heaps simpler and effective!

Thanks again.

--
Maki @ Canberra.AU


"Jacob Skaria" wrote:

Try the below macro..

Sub MyMacro()
Dim lngRow As Long, varCol As Variant, intMaxLen As Integer

varCol = InputBox("Enter the column to analyse")
If IsNumeric(varCol) Then varCol = CLng(varCol)

For lngRow = 2 To Cells(Rows.Count, varCol).End(xlUp).Row
If Len(Cells(lngRow, varCol)) intMaxLen Then
intMaxLen = Len(Cells(lngRow, varCol))
End If
Next

MsgBox intMaxLen
End Sub

If you are interested in a formula try the below. Please note that this is
an array formula. You create array formulas in the same way that you create
other formulas, except you press CTRL+SHIFT+ENTER to enter the formula. If
successful in 'Formula Bar' you can notice the curly braces at both ends like
"{=<formula}"

=MAX(LEN(D2:D1000))

--
Jacob (MVP - Excel)


"Maki" wrote:

Hi.

I'm trying to redesign a database, originally done in Access 2003, so
exported tables to Excel to analyse existing records, and in this instance,
maximum LEN in each column that's text.
I want to program a macro which:
1. asks, via InputBox, which column to analyse;
2. starting from the row after the header, counts LEN for the record and
moves on to the next row; and
3. returns, via MsgBox, MAX value amongst all LEN counted.

I've been trying to teach myself Excel VBA programming by following John
Walkenbach's "Excel 2007 Power Programming with VBA" but I'm obviously not
"getting it" and can't even program to do COUNTA, starting with InputBox and
ending with the value shown with MsgBox.

Please help!
--
Maki @ Canberra.AU

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
Figuring 24 Hours Per Day Jeff Excel Discussion (Misc queries) 5 July 22nd 09 08:35 PM
figuring tax jesseok New Users to Excel 2 October 22nd 08 02:11 PM
Figuring Age Sue Excel Worksheet Functions 2 March 18th 08 05:51 PM
Figuring Grades mkingsley Excel Worksheet Functions 2 April 5th 06 08:43 PM
Figuring hours scott45 Excel Worksheet Functions 0 August 29th 05 03:31 PM


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