如何在单独的工作表中找到特定的单元格值? [英] How to find a specific cell value in separate worksheet?
问题描述
我有一段代码在当前工作表中搜索特定单元格值的范围,然后在该列上执行操作。该宏由同一页面上的表单控制按钮启动。我需要将表单控件按钮移动到不同的工作表,但我不知道如何udpate我的代码只搜索sheet1而不是按钮中的按钮。
以下是使用与数据相同的工作表上的按钮时的代码。我只需要它来查看sheet1而不是当前工作表。
Dim R1 As Range
pre>
设置R1 =范围(A2:AX2)查找(BMA授权ID),范围(A2:AX2)查找(BMA授权ID)End(xlDown))
R1.Select
R1.Copy
R1.PasteSpecial粘贴:= xlPasteValues,操作:= xlNone,SkipBlanks _
:= False,Transpose:= False
解决方案使用 With ... End With语句设置范围/单元格的父工作表。
与工作表(Sheet1)'< ~~更改为适合
与.Range(.Range(A2:AX2)。查找(BMA授权ID)_
.Range(A2:AX2)。Find(BMA Authorization ID)。End(xlDown))
.value = .value与.Copy相同.PasteSpecial xlPasteValues
end with
以
结束请注意,所有的
范围(...)
现在是.Range(...)
。前缀周期(aka。
或完整停止)使所有范围的父工作表在With .. End With中引用。 p>I have a piece of code that searches a range in the current worksheet for a specific cell value and then does an action on that column. The macro is launched by a form control button on the same page. I need to move the form control button to a different worksheet but I am not sure how to udpate my code to only search in sheet1 and not in the sheet where the button in.
Below is my code that works when using the button on the same worksheet as the data. I just need it to look at sheet1 instead of the current sheet.
Dim R1 As Range Set R1 = Range(Range("A2:AX2").Find("BMA Authorization ID"), Range("A2:AX2").Find("BMA Authorization ID").End(xlDown)) R1.Select R1.Copy R1.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False
解决方案Use a With ... End With statement to set the range/cell parent worksheet.
with worksheets("Sheet1") '<~~change to suit with .Range(.Range("A2:AX2").Find("BMA Authorization ID"), _ .Range("A2:AX2").Find("BMA Authorization ID").End(xlDown)) .value = .value 'same as .Copy .PasteSpecial xlPasteValues end with end with
Note that all of the
Range(...)
are now.Range(...)
. The prefix period (aka.
or full stop) makes all of the ranges' parent the worksheet referenced within the With .. End With.这篇关于如何在单独的工作表中找到特定的单元格值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!