您好,我在vb.net和vba上遇到问题 [英] Hello i got a problem with vb.net and vba

查看:60
本文介绍了您好,我在vb.net和vba上遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我在使用VB.NET,Interop,Excel VBA时遇到了一些问题
我正在尝试搜索Excel文件test.xlsx Sheet2列H2-H10000
我想将变量用作搜索参数以计算重复项.
唯一的问题是我不知道如何通过Interop for Excel使用vb.net.
如果有人可以提供一些摘要或帮助我解决此问题的方法,将不胜感激.
这只是我整理来帮助您的一些代码:)

Hay guys,
I got a little problem using VB.NET, Interop, Excel VBA
I am trying to search an Excel file, testing.xlsx Sheet2 Column H2-H10000
I would like to use a variable as a search parameter for Counting the duplicates.
The only problem is I don’t know how to do this is vb.net with the Interop for Excel.
It would be much appreciated if someone could provide some Snippets or something to help me resolve this problem.
This is just some of the code that I have put together to help you help me :)

Imports Microsoft.Office.Interop
Imports System.Runtime.InteropServices

Class Form_Test

    Public MyWorkbook As New Excel.Application
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        MyWorkbook.Sheets("Sheet1").Select() ' This is the current Sheet
        Dim varsearch As String = TextBox10.Text ' The value will need to be searched and counted in an Excel Sheet
        Dim varresult As Integer = CInt(0)  ' This is the resulting number from the Counter

        ' Counter
' THIS is the line of which i have no idea of how to write it.
       varresult = MyWorkbook.Rows(MyWorkbook.ActiveCell.Column).'Count (varsearch) ToString() or something.

        MessageBox.Show("Your Repeating Value Is: " & varresult)

    End Sub
End Class


例如,我在我的应用程序中打开了一个Excel工作簿,并且我想在Sheet1的H2到H10000列中搜索字符串"Item1".我希望它在MessageBox中显示它返回的数字,因为我很快尝试在上面的代码中进行演示.
我一直在尝试使它工作一段时间,它有点累.

感谢您的阅读.


For example, I have an Excel workbook open with my Application and I want to search for the string "Item1" in Sheet1 Column H2 through H10000. I would like it to display the number it returns in a MessageBox, as I quickly tried to demonstrate in the code above.
I have been trying to get this to work for a while now, its getting a little tiring.

Thanks for reading.

推荐答案

将dim obj作为对象
obj =新对象("Excel.Application")
昏暗的表作为对象
obj.workbooks.open(浏览文件)
sheet = obj.worksheets(1)

对于a = 1到20000
如果sheet.range("h"& a).value = textbox.text.trim然后
msgbox(重复值")
退出
如果
结束 next
dim obj as object
obj=new object("Excel.Application")
dim sheet as object
obj.workbooks.open(browse your file)
sheet=obj.worksheets(1)

for a=1 to 20000
if sheet.range("h" & a).value=textbox.text.trim then
msgbox ("Duplicate value")
exit for
end if
next


由于某种原因我没有安装OFfice东西,所以我无法测试代码.
您的代码看起来像您跳过了几个步骤.
首先,您需要获取列,然后将列中的每个单元格与给定的文本进行比较(如果为true),然后如果为false,则将1加到计数器,然后移至下一个单元格


For some reason I don''t have the OFfice stuff installed So I cant test the code.
Your code looks like your skipping a couple of steps.
First you need to get the column, then compare each cell in the column to the given text if true then add 1 to the counter if false then move to the next cell

Something like
Dim textToSearchfor as string
textToSearchfor = iinputTextbox.text
Dim Counter as Integer
Counter = 0
For each cell in ColumnX
If currcell.Contains(textToSearchfor.tostring)
Counter add1

Next

Mgsbox(counter.tostring)



希望这会有所帮助



Hope this is somewhat helpful


这篇关于您好,我在vb.net和vba上遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆