dss28
Board Regular
- Joined
- Sep 3, 2020
- Messages
- 165
- Office Version
- 2007
- Platform
- Windows
i want to find the maximum value in column C corresponding to a value mentioned on Cell M1 of which data is given in Column B
the code:
max(if(B:B=M1,C:C) when written in one of the cells in the sheet with Ctrl+Shift+Enter gives the result correctly. however when applying the code in vba I am using the following code as found in this forum. i have the following code in module :
I have another code in userform to transfer the search value in cell M1 of the sheet.
I am interested in the value as given in cell Q1. The code does not work every time but when i change the value in the sheet in M1 cell and run the macro it works. but not through userform everytime and gives value 1 meaning the search text is not present.
i am not able to figure out what is wrong in the procedure or executing the code.
request for help
the code:
max(if(B:B=M1,C:C) when written in one of the cells in the sheet with Ctrl+Shift+Enter gives the result correctly. however when applying the code in vba I am using the following code as found in this forum. i have the following code in module :
VBA Code:
Public Sub MaxNo() '
Dim myVar As Long
ThisWorkbook.Sheets("Data").Activate
myVar = Evaluate("=MAX(IF(B:B=M1,C:C))")
ThisWorkbook.Sheets("Data").Range("O1").Value = myVar
ThisWorkbook.Sheets("Data").Range("Q1").Value = 1 + myVar
'End If
End Sub
I have another code in userform to transfer the search value in cell M1 of the sheet.
VBA Code:
Private Sub TextBox37_Change()
With Sheet14
ThisWorkbook.Sheets("Data").Range("M1").Value = UserForm3.TextBox37.Value '
Call MaxNo
End With
End Sub
I am interested in the value as given in cell Q1. The code does not work every time but when i change the value in the sheet in M1 cell and run the macro it works. but not through userform everytime and gives value 1 meaning the search text is not present.
i am not able to figure out what is wrong in the procedure or executing the code.
request for help