Ganesh Kumar Subramanian
New Member
- Joined
- Feb 17, 2016
- Messages
- 2
Hello,
I want to compare 2 logic in 2 different work sheets at same time if 2 logic is true then output will be shown.
I have written vba code for the same using IF logic, it is working but it takes too much time for running.
Hence i tried to change IF logic to INDEX MATCH function vba code, but it is not working it shown syntax error.
I attach my both IF logic and INDEX MATCH code for your reference. Please help me to solve this issue.
Logics:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Sheet1 = Active sheet
Sheet2 = PDMS EXTRACT
If sheet1->"/" & "B2" & "-X" = sheet2->A2 then
If sheet2->B2 = "SUBE" then
sheet1 D2 = sheet2 E2 'output
</code>
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Vba code using IF logic:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">ActiveWorkbook.ActiveSheet.Select
For i = 3 To 1000 'offline inst elevation
For n = 2 To 5000
If "/" & ActiveSheet.Cells(i, "B") & "-X" = Sheets("PDMS EXTRACT").Cells(n, "A") Or "/" & ActiveSheet.Cells(i, "B") = Sheets("PDMS EXTRACT").Cells(n, "A") Then
If Sheets("PDMS EXTRACT").Cells(n, "B") = "SUBE" Then
ActiveSheet.Cells(i, "D") = Sheets("PDMS EXTRACT").Cells(n, "E")
End If
End If
Next n
Next i
'......it's working fine but running time to slow.
</code>
</code>
</pre>
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">
Vba code using INDEX MATCH:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">ActiveSheet.Cells(i, "D") = Application.WorksheetFunction.Index(Sheets("PDMS EXTRACT").Range("A:E"), Application.WorksheetFunction.Match(1, ("/" & ActiveSheet.Cells(i, "B") & "-X" = Sheets("PDMS EXTRACT").Range("A:A")) * ("SUBE" = Sheets("PDMS EXTRACT").Range("B:B")), 0), 5) </code>but this code is not working, please check the code and tell me the proper code to execute this.
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"></code></pre></code></pre>
I want to compare 2 logic in 2 different work sheets at same time if 2 logic is true then output will be shown.
I have written vba code for the same using IF logic, it is working but it takes too much time for running.
Hence i tried to change IF logic to INDEX MATCH function vba code, but it is not working it shown syntax error.
I attach my both IF logic and INDEX MATCH code for your reference. Please help me to solve this issue.
Logics:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Sheet1 = Active sheet
Sheet2 = PDMS EXTRACT
If sheet1->"/" & "B2" & "-X" = sheet2->A2 then
If sheet2->B2 = "SUBE" then
sheet1 D2 = sheet2 E2 'output
</code>
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Vba code using IF logic:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">ActiveWorkbook.ActiveSheet.Select
For i = 3 To 1000 'offline inst elevation
For n = 2 To 5000
If "/" & ActiveSheet.Cells(i, "B") & "-X" = Sheets("PDMS EXTRACT").Cells(n, "A") Or "/" & ActiveSheet.Cells(i, "B") = Sheets("PDMS EXTRACT").Cells(n, "A") Then
If Sheets("PDMS EXTRACT").Cells(n, "B") = "SUBE" Then
ActiveSheet.Cells(i, "D") = Sheets("PDMS EXTRACT").Cells(n, "E")
End If
End If
Next n
Next i
'......it's working fine but running time to slow.
</code>
</code>
</pre>
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">
Vba code using INDEX MATCH:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">ActiveSheet.Cells(i, "D") = Application.WorksheetFunction.Index(Sheets("PDMS EXTRACT").Range("A:E"), Application.WorksheetFunction.Match(1, ("/" & ActiveSheet.Cells(i, "B") & "-X" = Sheets("PDMS EXTRACT").Range("A:A")) * ("SUBE" = Sheets("PDMS EXTRACT").Range("B:B")), 0), 5) </code>but this code is not working, please check the code and tell me the proper code to execute this.
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"></code></pre></code></pre>