Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Extracting column number of max value

I have the following VBA code to get "max value" and "the column number"
where max value is. I can get the max value, but not the column number. Any
suggestions?

Thanks.

Sub model()

For i = 1 To 16
Set eachrow = Range("data").Rows(i)
maxvalue = Application.WorksheetFunction.Max(eachrow)
colnumber = maxvalue.Column

Cells(i, 10) = maxvalue
Cells(i, 11) = colnumber

Next
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Extracting column number of max value

Green,

Sub test2()
For i = 1 To 16
Set eachrow = Range("data").Rows(i)
Cells(i, 10) = Application.WorksheetFunction.Max(eachrow)
Cells(i, 11) = Application.Match(Cells(i, 10).Value, eachrow, False)
Next i
End Sub

HTH,
Bernie
MS Excel MVP


"GreenInIowa" wrote in message
...
I have the following VBA code to get "max value" and "the column number"
where max value is. I can get the max value, but not the column number.
Any
suggestions?

Thanks.

Sub model()

For i = 1 To 16
Set eachrow = Range("data").Rows(i)
maxvalue = Application.WorksheetFunction.Max(eachrow)
colnumber = maxvalue.Column

Cells(i, 10) = maxvalue
Cells(i, 11) = colnumber

Next
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Extracting column number of max value

I should note that the column number will be relative within the range
"data", which is fine if data starts in column 1. Other wise, you could
either change
Cells(i, 11) = Application.Match(Cells(i, 10).Value, eachrow, False)
to
Cells(i, 11) = Application.Match(Cells(i, 10).Value, eachrow.EntireRow,
False)

or add the number (less one) of the first column of data.

HTH,
Bernie

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Green,

Sub test2()
For i = 1 To 16
Set eachrow = Range("data").Rows(i)
Cells(i, 10) = Application.WorksheetFunction.Max(eachrow)
Cells(i, 11) = Application.Match(Cells(i, 10).Value, eachrow, False)
Next i
End Sub

HTH,
Bernie
MS Excel MVP


"GreenInIowa" wrote in message
...
I have the following VBA code to get "max value" and "the column number"
where max value is. I can get the max value, but not the column number.
Any
suggestions?

Thanks.

Sub model()

For i = 1 To 16
Set eachrow = Range("data").Rows(i)
maxvalue = Application.WorksheetFunction.Max(eachrow)
colnumber = maxvalue.Column

Cells(i, 10) = maxvalue
Cells(i, 11) = colnumber

Next
End Sub





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Extracting column number of max value

MATCH function. This is great, Bernie.

Thanks!




"Bernie Deitrick" wrote:

Green,

Sub test2()
For i = 1 To 16
Set eachrow = Range("data").Rows(i)
Cells(i, 10) = Application.WorksheetFunction.Max(eachrow)
Cells(i, 11) = Application.Match(Cells(i, 10).Value, eachrow, False)
Next i
End Sub

HTH,
Bernie
MS Excel MVP


"GreenInIowa" wrote in message
...
I have the following VBA code to get "max value" and "the column number"
where max value is. I can get the max value, but not the column number.
Any
suggestions?

Thanks.

Sub model()

For i = 1 To 16
Set eachrow = Range("data").Rows(i)
maxvalue = Application.WorksheetFunction.Max(eachrow)
colnumber = maxvalue.Column

Cells(i, 10) = maxvalue
Cells(i, 11) = colnumber

Next
End Sub




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
Help!!! Extracting a number to line up with a different number lpdc Excel Discussion (Misc queries) 4 June 13th 06 08:40 PM
extracting a number Hernan Excel Programming 6 July 14th 05 09:47 PM
Populate a column by extracting unique values from another column? Mike Palmer Excel Worksheet Functions 2 June 10th 05 03:21 PM
Extracting same column from large number of workbooks BillC Excel Worksheet Functions 3 February 18th 05 09:01 PM
Extracting the column letter and row number Todd Huttenstine Excel Programming 4 December 15th 04 10:06 PM


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