如何检索vba中的第一个非空白单元格和任何动态行的值

时间:2017-09-25 06:06:47

标签: excel vba excel-vba row

<?php
    $servername = "localhost";
    $username = "root";
    $password = "pravin";
    $mysql_conn = new mysqli($servername, $username, $password);
        if ($mysql_conn->connect_error) {
             die("Connection failed: ". $mysql_conn->connect_error);
 }

echo "Connected successfully";
$name = $_POST["microorganism"];
echo $name;
$db_selected = mysql_select_db('yieldofvanillin', $mysql_conn);
if (!$db_selected){
    die ('Can\'t use  : ' . mysql_error());
}
$query = "SELECT * FROM vanillin WHERE Microorganism = '$name' ";
$result = $mysql_query($query);
while ($line = myql_fetch_array($result, MYSQL_ASSOC)) {
    echo $line["Substrate"];
    echo $line["products"];
    echo $line["Microorganism"];
    echo $line["yield"];
    echo $line["Reference"];
}

mysql_close($mysql_conn);
?>

上面的代码给出了类型不匹配错误13。

请告知我的错误,或建议采用其他方法。

2 个答案:

答案 0 :(得分:1)

尝试下面的代码,代码注释中的解释:

Dim rngFound  As Range
Dim LastCol As Long
Dim nonBlankCell As Variant

With Worksheets("Sheet1") ' <-- modify to your sheet's name
    ' -- get last column in a specific row by using the Find function --
    Set rngFound = .Rows(5).Find(What:="*", Lookat:=xlPart, LookIn:=xlFormulas, _
                    SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)

    If Not rngFound Is Nothing Then ' Find was successful
        LastCol = rngFound.Column ' get last Column with data
        nonBlankCell = rngFound.Value
    End If

End With

答案 1 :(得分:0)

Cells(Columns.Count, 5)替换为Cells(5, Columns.Count).End(xlToLeft)以获取

Set rngFound = Rows(5).Find("*", Cells(5, Columns.Count).End(xlToLeft), xlFormulas, , xlByColumns, xlNext)

试试这个

Sub Find_Cell()
    Dim rngFound  As Range
    Set rngFound = ThisWorkbook.Sheets("Sheet1").Rows(5).Find(What:="*", LookIn:=xlValues)

    If rngFound Is Nothing Then
        MsgBox "All cells are blank."
    Else
        MsgBox "First Cell Address: " & rngFound.Address
        MsgBox "First Cell Value: " & rngFound.Value
    End If
End Sub

如果您还想查找公式等于空白的非空白单元格,而不是LookIn:=xlValues使用LookIn:=xlFormulas

相关问题