简体   繁体   English

VBA Excel +使用匹配功能

[英]VBA Excel + using match function

I'm having some kind of problem in a piece of code. 我在一段代码中遇到了某种问题。 I need to find values in a excel book and then copy it to another. 我需要在Excel书中找到值,然后将其复制到另一本书中。 The thing is that i need to copy it concept by concept in the right place. 问题是我需要在正确的位置逐个概念地复制它。 The problem is that the file doesnt come every week in the same order. 问题在于文件并非每周都以相同的顺序出现。 So i need to find the concept and then copy the next cell that is the value of that concept. 因此,我需要找到该概念,然后复制该概念值的下一个单元格。 First of all i use need to locate the correct line so i can start copying (this part is easy and its done). 首先,我需要找到正确的行,以便可以开始复制(这部分很容易完成)。 Secondly, having the correct line, i need to find the concept, which in this example im going to use the "619". 其次,在正确的行上,我需要找到概念,在本示例中,我将使用“ 619”。 After having find the location of this value i store the value in "c_audiovisual". 找到该值的位置后,我将该值存储在“ c_audiovisual”中。

 On Error GoTo ErrhandlerCAV
         lRowC_AV = Application.WorksheetFunction.Match(619, Range("A" & line & ":FI" & line), 0) + 1

       'On Error GoTo ErrhandlerCAV
Continue:
        If errorCAV = 1 Then
                c_audiovisual = 0
                errorCAV = 0
        Else
                c_audiovisual = ActiveSheet.Cells(line+ m2, lRowC_AV).Value
        End If

I've made a escape in case that this concept isn't present in that line (which sometimes occurs). 万一该行中不存在此概念(有时会发生),我已经进行了转义。

Sometimes this piece of code works, and other it doesn't. 有时这段代码行得通,而其他的则行不通。 When i'm on debug mode (pressing F8) it works. 当我处于调试模式(按F8)时,它可以工作。 And when i use small files to look for the values it works. 当我使用小文件查找其值时。 On bigger files sometimes don't. 在较大的文件上有时不这样做。

Any ideas? 有任何想法吗?

I faced similar issues. 我遇到了类似的问题。 I fixed it with using ThisWorkbook.Sheets("MySheet").Range(...) inside the Match function. 我使用Match函数中的ThisWorkbook.Sheets(“ MySheet”)。Range(...)修复了该问题。 Or try ActiveWorkbook as applicable. 或尝试使用ActiveWorkbook(如果适用)。 Let me know if this worked. 让我知道这是否有效。 Curious to know. 好奇地知道。

Btw I noticed column and row number both are "line". 顺便说一句,我注意到列号和行号都是“行”。 Is that a mistake? 那是个错误吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM