有没有办法在excel宏中使用find函数来改变用户输入的值?
我想要做的是在一张纸上放置用户输入字段,用户将文本输入到单元格中。然后,它们可以运行一个选择不同工作表的宏,然后在查找功能中使用该输入的文本。
What I am trying to do is to have a user input field on one sheet, where the user types text into a cell. They can then run a macro which selects a different sheet and then uses that inputted text in a find function.
找到文本后,需要选择文本所在的整个列,以及所有单元格直到下一个填充的单元格(在行发现字/短语所在)。这些单元格将被删除。
Once the text is found, the entire column which the text is found needs to be selected, along with all the cells to the right up to the next populated cell (in the row the 'found' word/phrase is located). These cells will then be deleted.
我有两个主要问题。我似乎找不到如何使用 Find
函数与一个变化的值(我说值,但我的意思是任何单词,短语等被放入用户输入领域)。我只能搜索一个特定的值,而不能引用用户输入的字段。
I am having two main problems. I can't seem to find how to use the Find
function with a changing value (I say value but I mean whatever word, phrase, etc. is put into the user inputted field). I am able to only search for a specific value and can't reference the user inputted field instead.
第二个问题是选择列 - 一旦 Find
函数找到用户输入的值/单词/短语,它选择它所在的单元格。我希望它选择整个列(以及右侧的列到特定行中的下一个填充单元格)。
The second problem is selecting the column- once the Find
function finds the user inputted value/word/phrase, it selects the cell it is in. I would like it to select the entire column (and the columns to the right of it up to the next populated cell in a specific row).
这是一个类似的问题,因为我似乎无法引用用户输入的值/单词短语的列,因为它将不断变化。我只能选择一个列,问题是它选择的列可能不需要被删除,下一次宏运行时,它的工作表正在找到不断更新的值。
This is a similar problem as I can't seem to reference the column in which the user inputted value/word phrase is found as it will constantly change. I am only able to select a certain column, the problem being the column it selects will probably not need to be deleted the next time the macro is run as the sheet it is finding the values in is constantly updated.
这是迄今为止的代码。
Here is the code I have so far.
Sub Macro3()
Sheets("Instructions").Select
Range("C53").Select
Selection.Copy
Sheets("Forecast").Select
Cells.Find(What:="4150T83G01", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Columns("BW:BY").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
End Sub
So basically, the range C53 will never change. I always want that to be where the user inputs the word/phrase/value to be found.
代码说 Cells.Find(What:=4150T83G01
- 我需要这个不要该特定值,而是指单元格C53中说明
表中输入的用户输入的词/短语/值。
Where the code says Cells.Find(What:="4150T83G01"
- I need this to not refer to that specific value but instead refer to the user inputted word/phrase/value on the "Instructions"
sheet in cell C53.
最后,代码说列(BW:BY)。选择
- 我需要这个来指代用户输入单词/短语的列找到/值以及找到的单元格右边的列直到下一个填充单元格,而不是特定列 BW:BY
。
And finally, where the code says Columns("BW:BY").Select
- I need this to refer to the column in which the user inputted word/phrase/value is found as well as the columns to the right of the found cell up until the next populated cell, not the specific columns BW:BY
.
我希望这是有道理的,任何帮助都非常感谢!谢谢!
I hope that makes sense, and any help is greatly appreciated! Thank you!
看来你正在使用一个记录的宏?
要做这些事情你不仅需要记录宏。
It seems that you're trying with a recorded macro? To do these kind of things you will need more than just recording macros.
Sub Macro3()
Dim strFind As String
Dim rngFind As Range
Dim i As Integer
strFind = Sheets("Sheet2").Range("C3").Value
Set rngFind = Sheets("Sheet1").Cells.Find(What:=strFind, LookAt:=xlPart)
'check if value is found
If Not rngFind Is Nothing Then
i = 0
Do While rngFind.Offset(0, i + 1) = ""
i = i + 1
Loop
rngFind.Resize(1, i + 1).EntireColumn.delete Shift:=xlShiftToLeft
End If
End Sub