maabadi
Well-known Member
- Joined
- Oct 22, 2012
- Messages
- 2,681
- Office Version
- 2019
- 2016
- Platform
- Windows
What is Problem of this code. It return Countif =0 always.
Please check lookup function also.
Please check lookup function also.
VBA Code:
Sub SumLookUp()
Dim cell As Range
Dim x As Long
Dim firstrow As Long
Dim firstColumn As Long
Dim lastrow As Long
Dim sumcolumn As Long
Dim y As Long
Dim InputData As Range
Dim Sumrange As Range
Dim SumLookUp As Long
Set InputData = Range("A2:A44")
Set Sumrange = Range("B2:B44")
y = 0
firstrow = InputData.Row
firstColumn = InputData.Column
sumcolumn = Sumrange.Column
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For Each cell In InputData
Debug.Print Cells(firstrow, firstColumn).Value
Debug.Print Cells(cell.Row, firstColumn).Value
Debug.Print Cells(cell.Row, cell.Column).Value
If Application.WorksheetFunction.CountIf(Range(Cells(firstrow, firstColumn), Cells(cell.Row, firstColumn)), Range(Cells(cell.Row, cell.Column))) = 1 Then
x = Evaluate("=Application.WorksheetFunction.Lookup(2, 1 / (Range(Cells(firstrow, firstColumn), Cells(lastrow, firstColumn))) = Range(Cells(cell.Row, cell.Column)), Range(Cells(firstrow, sumcolumn), Cells(lastrow, sumcolumn)))")
y = y + x
Else
Debug.Print Application.WorksheetFunction.CountIf(Range(Cells(firstrow, firstColumn), Cells(cell.Row, firstColumn)), Range(Cells(cell.Row, cell.Column)))
End If
Next cell
SumLookUp = y
MsgBox SumLookUp
Debug.Print y
End Sub