简体   繁体   English

VBA excel搜索列和行然后插入到该单元格

[英]VBA excel searching columns and rows then insert to that cell

I'm new in VBA excel, now I require to develop a Marco to search through a table and insert the value to that particular cell.我是 VBA excel 的新手,现在我需要开发一个 Marco 来搜索表格并将值插入该特定单元格。 I know there is a technique which to loop through all the column and row, but it create more problems to my code.我知道有一种技术可以遍历所有的列和行,但它会给我的代码带来更多问题。 Any other technique can achieve that?任何其他技术都可以做到这一点?

Suppose I have a table:假设我有一张桌子:

How can I search for Week 7 and Bread and I want to insert value of 10 in that cell in Marco?如何搜索 Week 7 和 Bread 并且我想在 Marco 的那个单元格中插入 10 的值? Thank you.谢谢你。

Without using a loop you can get the target row and columns by using .Find() to get the row ans column numbers and then Cells (rownumber, columnnumber) to store the data.在不使用循环的情况下,您可以通过使用 .Find() 获取行和列号,然后使用 Cells (rownumber, columnnumber) 来存储数据来获取目标行和列。

The code below should give you a way forward下面的代码应该给你一个前进的方向

Sub insert()
Dim myColumn As Range
Dim myRow As Range

Set myColumn = Sheets("Sheet1").Rows("2:2").Find("Week 2")
Set myRow = Sheets("Sheet1").Columns("A:A").Find("Nuts")

Sheets("Sheet1").Cells(myRow.Row, myColumn.Column) = "10"

End Sub结束子

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

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