Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 对于每个循环,其他部分失败_Excel_Vba - Fatal编程技术网

Excel 对于每个循环,其他部分失败

Excel 对于每个循环,其他部分失败,excel,vba,Excel,Vba,我会向你寻求帮助。我已经做了很多次了,但这一次我无法忍受 我把ProductID列分为两页,其中一页有它们的描述,我希望将此描述转移到另一页。如果ProdID不可用,则必须说明不可用。作为一项功能 For Each product In Intersect(searcharea.Columns(1).Cells, searcharea.Parent.UsedRange) If product.Text = searchedvalue.Text Then descripti

我会向你寻求帮助。我已经做了很多次了,但这一次我无法忍受

我把
ProductID
列分为两页,其中一页有它们的描述,我希望将此描述转移到另一页。如果
ProdID
不可用,则必须说明
不可用
。作为一项功能

For Each product In Intersect(searcharea.Columns(1).Cells, searcharea.Parent.UsedRange)
    If product.Text = searchedvalue.Text Then
        description = Trim(product.Offset(0, 1).Text)
    Else description = "Not available"
    End If
Next product
productdescription = description

我得到的所有描述都不可用。

我使用类似的函数重试,然后可能会提供与您预期相同的结果,我发现
Exit For
在循环中非常重要,否则在大多数情况下它总是返回“not found”,希望对您有所帮助:)

B列是我输入用户定义函数的位置 出现了几个问题:

  • 当“子”更适合时,为什么要使用“函数”
  • “xCell”是打字错误吗
  • “irow”在哪里声明/更新
我试着用我的sub vs.function说:

For Each Product In Intersect(searcharea.Columns(1).Cells, searcharea.Parent.UsedRange)

    If Product.Text = searchedvalue.Text Then
        Description = Trim(xCell.Offset(0, 1).Text)
    Else
        Description = "Not available"
    End If

    cells(irow,2).value = Description
 
Next Product

你们写的东西可以用,但实际上是换行,而不是
将是我希望在这里看起来不错的东西(为了更好的可读性)。不幸的是,它不适合我。Productdescription本身就是函数的名称,VBA不允许我这样做。当我执行productdescription=description时,它只在最后一个entry@PᴇʜYa,宏自动填充:当我复制到我的excel进行测试时,我认为这是excel 365中的新更新,尽管我个人不喜欢它哈哈。@lifeofnobie也许你的问题出在Productdescription函数上,很难说到底是什么问题?很遗憾,由于数据是机密的,所以无法共享数据。我想要实现的是,如果从第二张图纸中的第一张图纸列A(1)获取ID,则让此函数从第二张图纸获取偏移量(0,1)。如果ID不可用,那么它应该说“不可用”。因此,该函数的工作方式类似于查找,但客户端需要将其作为单独的函数。例如productdescription=(A2,Sheet2!$A$1:$B$100)应该给出“铲”,因为A2 sheet1中有ID_01,第二张表中的ID_01有“铲”的描述。此功能工作正常,但在“不可用”部分丢失。是的,它是打字错误,必须稍作更改。很抱歉Irow不是我的解决方案
For Each Product In Intersect(searcharea.Columns(1).Cells, searcharea.Parent.UsedRange)

    If Product.Text = searchedvalue.Text Then
        Description = Trim(xCell.Offset(0, 1).Text)
    Else
        Description = "Not available"
    End If

    cells(irow,2).value = Description
 
Next Product