遍历范围和检查值(Excel VBA)

时间:2018-06-23 11:56:31

标签: excel vba excel-vba

我已经编写了一个简单的VBA代码以遍历范围以检查特定值,如果该值为true,则它将布尔触发器切换为False。

但是,我的代码不起作用。即使我将“ 12345”放置在范围内的某个位置,它仍然返回Infochk = True。

代码

Dim InfoChk As Boolean
InfoChk = True
LastRow = Sheets("Sheet1").Cells(Rows.count, "B").End(xlUp).row
For i = 7 To LR
    With Worksheets("Sheet1")
        If .Cells(i, 6).Value = "12345" Then
            MsgBox ("gotcha")
            InfoChk = False
            Exit For
        End If
    End With
Next i
MsgBox (InfoChk)

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

使用LastRow:

public void GetVersionFromServer(String BuildVersionPath)
{
URL u;
    try {
        u = new URL(BuildVersionPath.toString());

        HttpURLConnection c = (HttpURLConnection) u.openConnection();
        c.setRequestMethod("GET");
        c.setDoOutput(true);
        c.connect();

        InputStream in = c.getInputStream();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        byte[] buffer = new byte[1024]; 


        int len1 = 0;
        while ( (len1 = in.read(buffer)) != -1 )
        {
            baos.write(buffer,0, len1); 
        }

        String temp = "";
        String s = baos.toString();

        for (int i = 0; i < s.length(); i++)
        {
            i = s.indexOf("=") + 1;
            while (s.charAt(i) == ' ')
            {
                i++; 
            }
            while (s.charAt(i) != ';'&& (s.charAt(i) >= '0' && s.charAt(i) <= '9' || s.charAt(i) == '.'))
            {
                temp = temp.toString().concat(Character.toString(s.charAt(i))) ;
                i++;
            }
            //
            s = s.substring(i); 
            temp = temp + " "; 
        }
        String[] fields = temp.split(" ");

        VersionCode = Integer.parseInt(fields[0].toString());
        VersionName = fields[1].toString();

        baos.close();
    }

enter image description here