PDA

View Full Version : [SOLVED:] Compare two cell in two columns and present in new column



elmnas
05-26-2015, 06:47 AM
Hello people

I should need help to correct the code I don't get the result I want.

in Column J and K If the text are equal like here "IND" and "IND"
then take value in Column B same row = (88) -1 / 12(Column B same row)

( present it in Column T same row
result = 8 in same row but Column T

see picture
13516


I want this result instead

13517



Here is my code




Sub test()
Dim i&, j&
Application.ScreenUpdating = False
With WorksheetFunction
For i = 1 To .Max(Cells(Rows.Count, "J").End(xlUp).Row, Cells(Rows.Count, "K").End(xlUp).Row)
If Cells(i, "J") = Cells(i, "K") And Len(Cells(i, "B")) <> 0 And Cells(i, "AB") <> 0 Then
j = j + 1
Cells(j, "T") = Cells(i, "B") - 1 / Cells(i, "AB")
End If
Next i
End With


End Sub


Could someone help me to correct my code?



Thank you in advance

mancubus
05-26-2015, 11:26 PM
how did you manage to produce 8 by subtracting 1/88 from 12?

write your formula which will produce the desired result in wprksheet and copy that formula here.

elmnas
05-26-2015, 11:36 PM
how did you manage to produce 8 by subtracting 1/88 from 12?

write your formula which will produce the desired result in wprksheet and copy that formula here.

I don't understand your question really

but I want

12 - 1 = 11 then 88/11 = 8

mancubus
05-27-2015, 01:50 AM
it was a question derived from Cells(j, "T") = Cells(i, "B") - 1 / Cells(i, "AB") and i wanted to understand the formula.

using only column letters it is T = AB / (B - 1)

B = 12, AB = 88 => T =8

try:


Sub test()

Dim i&, LastRow&

Application.ScreenUpdating = False

With ActiveSheet
LastRow = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
For i = 1 To LastRow
If .Cells(i, "J") = .Cells(i, "K") And Len(.Cells(i, "B")) And Len(.Cells(i, "AB")) Then
.Cells(i, "T") = .Cells(i, "AB") / (.Cells(i, "B") - 1)
End If
Next i
End With

End Sub

elmnas
05-27-2015, 07:25 AM
Thank you Mancubus solved!