EXCEL FORMULA / MACRO:返回同一列

时间:2016-05-02 20:42:40

标签: excel vba excel-vba

这里是场景:我有两列#34;线程代码"和"时间"。我需要遍历线程代码(示例数据中的A列)以查找下一个匹配项并在第3列中返回它的Time。如果已找到线程代码,则公式应跳过它,但继续循环遍历列中的其余值。

以下是示例数据:

    Command & Thread               Time         End Time (Expected Result)
clearVideoCache0x16e6ef000    1461178638535256  1461178638575052
clearVideoCache0x16e6ef000    1461178638575052  Already Used
clearVideoCache0x16e0a3000    1461178639330011  1461178639366057
clearVideoCache0x16e0a3000    1461178639366057  Already Used
session/start0x16e6ef000      1461178648045939  1461178648451464
session/start0x16e6ef000      1461178648451464  Already Used
user0x16e6ef000               1461178648505997  1461178648925134
user0x16e6ef000               1461178648925134  Already Used
system/properties0x16e6ef000  1461178648992088  1461178649223747
system/properties0x16e6ef000  1461178649223747  Already Used
activation/device0x16e6ef000  1461178649319258  1461178649949353
activation/device0x16e6ef000  1461178649949353  Already Used
subscription/0x16e6ef000      1461178650000950  1461178650391812
recordings0x16eb4f000         1461178650019638  1461178651156481
subscription/0x16e6ef000      1461178650391812  Already Used
subscription/0x16e6ef000      1461178650443640  1461178650877673
subscription/0x16e6ef000      1461178650877673  Already Used
user/subscriptions0x16e6ef000 1461178650926804  1461178651900302
recordings0x16eb4f000         1461178651156481  Already Used
user/subscriptions0x16e6ef000 1461178651900302  Already Used

到目前为止,这是我的代码:

"=IFERROR(INDEX($E$1:INDEX(E:E,MATCH(""ZZZ"",D:D)),AGGREGATE(15,6,ROW($D$1:INDEX(D:D,MATCH(""ZZZ"",D:D)))/($D$1:INDEX(D:D,MATCH(""ZZZ"",D:D))=D2),COUNTIF($D$1:$D2,D2))), ""NO MATCH"")"

但是,这会返回我用于查找的相同值,而不是列中的下一个匹配值。如果没有找到匹配," NO MATCH"消息应显示在单元格中。此外,我需要为该公式应用宏。任何想法如何实现这一目标?

1 个答案:

答案 0 :(得分:0)

请尝试使用以下代码。

<?php
if (!isset($_SESSION)) {
    session_start();
}
include_once('class.phpmailer.php');
$first = @$_POST['name'];
$last = @$_POST['last'];
$email = @$_POST['email'];
ob_start();
?>
<table width="361" align="center" style="border-bottom:solid #848484 thin; border-left:solid #848484 thin; border-top:solid #848484 thin; border-right:solid #848484 thin;">
    <tr>
        <td colspan="2" align="center" style="border-bottom:solid #848484 thin; border-left:solid #848484 thin; border-top:solid #84848``4 thin; border-right:solid #848484 thin;">Contact Form</td>
    </tr> 
    <tr>
        <td width="21" style="border-bottom:solid #848484 thin; border-left:solid #848484 thin; border-top:solid #848484 thin; border-right:solid #848484 thin;"><span class="style3">First Name</span></td>
        <td width="39" style="border-bottom:solid #848484 thin; border-left:solid #848484 thin; border-top:solid #848484 thin; border-right:solid #848484 thin;"><span class="style3"><?php echo $first; ?></span></td>
    </tr>
    <?php if ($last == 0) { ?>
    <?php } else { ?>
        <tr>
            <td width="21" style="border-bottom:solid #848484 thin; border-left:solid #848484 thin; border-top:solid #848484 thin; border-right:solid #848484 thin;"><span class="style3">Last Name</span></td>
            <td width="39" style="border-bottom:solid #848484 thin; border-left:solid #848484 thin; border-top:solid #848484 thin; border-right:solid #848484 thin;"><span class="style3"><?php echo $last; ?></span>
            </td>
        </tr>
    <?php } ?>
    <tr>
        <td width="21" style="border-bottom:solid #848484 thin; border-left:solid #848484 thin; border-top:solid #848484 thin; border-right:solid #848484 thin;"><span class="style3">E-Mail</span></td>
        <td width="39" style="border-bottom:solid #848484 thin; border-left:solid #848484 thin; border-top:solid #848484 thin; border-right:solid #848484 thin;"><span class="style3"><?php echo $email; ?></span></td>
    </tr>       
</table>
<?php
$message = ob_get_clean();
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = false;
$mail->SMTPAuth = false;
$mail->SetFrom('do-not-reply@example.com', 'Example');
$mail->AddAddress('yts.sachin@gmail.com');
$mail->Subject = "Call Back Request From example.com";
$mail->MsgHTML($message);

if ($mail->Send())
    echo $mail = "Mail Sent!";
else
    echo $mail = "There is an error while sending a mail:" . $mail->ErrorInfo;
?>

工作证明

enter image description here

请查看预期结果中出现错误的红色标记文字。

编辑2

根据你的评论表,它将如下所示。请确认一下?

enter image description here