使用验证数据下拉列表时遇到问题。 如果符合条件,我已经注册了应该显示下拉列表的宏(下拉列表基于命名范围)。当我手动输入并将数据验证添加到所选范围时,它可以正常工作,但是当我尝试使用宏时,它会失败并在行.Add处显示错误1004。注册宏并在之后运行它也是不可能的。 这是代码:
<th><input type="text" name="from" id="from" class="tcal"> to <input type="text" name="to" id="to" class="tcal"><br><br></th>
<th><input type="submit" class="button" value=""></th>
<?php
$con = mysqli_connect('localhost','root','');
mysqli_select_db($con, 'efms');
$results_per_page = 20;
$from=@$_POST['from'];
$to=@$_POST['to'];
$sql="SELECT *, SUM(rqty), SUM(iqty), SUM(bbal), COUNT(item), COUNT(description) FROM issuances WHERE trandate BETWEEN '$from' AND '$to' GROUP BY item, description, category ORDER BY item, description, category ASC";
$result = mysqli_query($con, $sql);
$number_of_results = mysqli_num_rows($result);
$number_of_pages = ceil($number_of_results/$results_per_page);
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
$this_page_first_result = ($page-1)*$results_per_page;
$from=@$_POST['from'];
$to=@$_POST['to'];
$sql="SELECT *, SUM(rqty), SUM(iqty), SUM(bbal), COUNT(item), COUNT(description) FROM issuances WHERE trandate BETWEEN '$from' AND '$to' GROUP BY item, description, category ORDER BY item, description, category ASC LIMIT " . $this_page_first_result . ',' . $results_per_page;
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result)) {
$id=$row['id'];
$item=$row['item'];
$description=$row['description'];
$rqty=$row['SUM(rqty)'];
$iqty=$row['SUM(iqty)'];
$bqty=$row['bqty'];
$bbal=$row['SUM(bbal)'];
$totqtyb=$bbal+$rqty-$iqty;
echo "<th width='80px' class='text-left left bottom right'>$item ($description)</th>";
echo "<th width='80px' class='right bottom'>$bbal</th>";
echo "<th width='100px' class='right bottom'></th>";
echo "<th width='100px' class='right bottom'></th>";
echo "<th width='80px' class='right bottom'>$rqty</th>";
echo "<th width='100px' class='right bottom'></th>";
echo "<th width='100px' class='right bottom'></th>";
echo "<th width='100px' class='right bottom'>$rqty</th>";
echo "<th width='80px' class='right bottom'>$iqty</th>";
echo "<th width='100px' class='right bottom'></th>";
echo "<th width='100px' class='right bottom'></th>";
echo "<th width='100px' class='right bottom'>$totqtyb</th>";
echo "</tr>";
}
for ($page=1;$page<=$number_of_pages;$page++) {
echo '<b><a href="efms.php?page=' . $page . '"> ' . $page . ' </a></b>';
}
?>
我通过论坛搜索并谷歌了解,但我发现的所有答案在这种情况下都不起作用。 命名范围(list_a,list_b)存在于另一张工作簿中。
答案 0 :(得分:1)
尝试将;
中的,
更改为Formula1
另外,尝试合并CHOOSE
函数。类似的东西:
Formula1:="=CHOOSE(IF(AND($L2<DATE(2014,5,1),$M2>DATE(2015,4,30)),1,2),list_a,list_b)"
答案 1 :(得分:0)
在编写这样的公式时,会忽略局部区域格式,因此在单元格中正常工作的分号将会失败。您需要更改以下公式:
.Add Type:=xlValidateList, Formula1:="=IF(AND($L2<DATE(2014;5;1);$M2>DATE(2015;4;30));list_a;list_b)"
要:
.Add Type:=xlValidateList, Formula1:="=IF(AND($L2<DATE(2014,5,1),$M2>DATE(2015,4,30)),list_a,list_b)"
答案 2 :(得分:0)
使用Range.Activate并带有ActiveCell.Validation 就像在#3上建议的
https://www.mrexcel.com/board/threads/adding-data-validation-via-vba-returns-1004-error.331279/
它对我有帮助