简体   繁体   English

编写一个 Excel 宏来查找和赋值,复制该值并粘贴到单元格中

[英]Write an Excel macro to find and value, copy that value and paste into a Cell

I'm looking to write an excel VBA macro to我想写一个 excel VBA 宏到

  • find a value "New Member" in a table (named "array1")在表中查找值“新成员”(名为“array1”)
  • look to and copy the cell 5 cells to the left of the found item查看并复制找到的项目左侧的单元格 5 个单元格
  • paste into Cell G5粘贴到单元格 G5
  • if the value "New Member" isn't found write "not found" in cell G5如果未找到值“新成员”,则在单元格 G5 中写入“未找到”

I've tried various versions of我试过各种版本的


        Cells.Find("New Member").Activate
        ActiveCell.Offset(0, -5).Range("array1").Select
        Selection.Copy
     Range("????").Select
         ActiveSheet.Paste
        If aaa = "" Then
        MsgBox "nope"
        Else

        Range("G5").Select
        ActiveSheet.Paste

My vba excel macro skills are very new.我的vba excel宏技能很新。 Thanks!谢谢!

You can do it without all the Select/Activate stuff.你可以在没有所有选择/激活的东西的情况下做到这一点。

Dim rngFound As Range

Set rngFound = Range("Array1").Cells.Find("New Member")
  
If rngFound Is Nothing Then
    Range("G5").Value = "Not Found"
Else
    rngFound.Offset(,-5).Resize(,5).Copy Range("G5")
End If

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

相关问题 Excel宏,要基于另一个单元格值复制和粘贴单元格值? - Excel macro, to copy and paste a cell value based on another cell value? Excel宏查找包含数据的最后一个单元格,然后从该值复制整个页面并粘贴到powerpoint中 - Excel macro to find the last cell with data then copy the whole page from that value and paste into powerpoint 基于单元格值的Excel宏复制范围粘贴偏移量 - Excel Macro Copy Range Paste offset based on cell value Excel宏,根据另一个单元格值复制和粘贴多个单元格? - Excel macro, to copy and paste a multiple cells based on another cell value? 宏以基于单元格值复制范围和粘贴 - Macro to Copy Range and Paste Based on Cell Value Excel宏:如果单击了单元格A,则复制单元格B并粘贴为值,然后将位置返回到单元格A - Excel Macro: If Cell A is clicked, copy Cell B and paste as value, then return position to Cell A Excel COPY PASTE值使用宏 - Excel COPY PASTE value using macro Excel宏查找并复制相应的单元格在值上应用公式 - Excel Macro find and copy corresponding cell apply formula on the value 宏根据特定单元格的值向左重复复制粘贴 - Macro to repeat copy paste to the left based on the value of a particular cell VBA 根据日期将工作表 1 中的单元格值复制/粘贴到工作表 2 的宏 - VBA Macro to copy/paste cell value from sheet 1 to 2 based on date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM