选择列并从其他单元格中找到值 [英] Select column and find the value from other cell

查看:52
本文介绍了选择列并从其他单元格中找到值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要选择列"D:D",所以我这样做了.然后,我需要在其他单元格的列值中查找.所以我需要做的:

I needed to select column "D:D" so I did. Then I needed to find in column value of other cell. So what I need to do:

  1. 我在"J5"单元格中获得了价值.
  2. 我需要在D:D中找到该值
  3. 我需要向右移动一个单元格
  4. 我需要复制单元格中的所有内容(例如-E2)
  5. 将其粘贴到"J6"中

所有内容都在一张纸中,但结果将在另一张纸中使用.这是为了明天的学校项目.我整个周末都在努力寻找答案,但是我不能自己做,我的大脑被洗了.

Everything is in one sheet but the result will be used in other sheet. It's for tommorow school project. I was trying all weekend to grab answer, but I can't do it on my own and my brain is washed.

代码:

Columns("B:B").Select
Selection.Find(What:="VA22GU1", After:=ActiveCell, LookIn:=xlFormulas, _
  LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
  MatchCase:=False, SearchFormat:=False).Activate

推荐答案

所以我需要做什么:

So what I need to do:

1.我在"J5"单元格中获得了价值.

1.I got value in "J5" cell.

2.我需要在D:D中找到该值

2.I need to find that value in D:D

3.我需要向右移动一个单元格

3.I need to move one cell to right

4.我需要复制单元格中的所有内容(例如-E2)

4.I need to copy everything from cell (for example - E2)

5.将其粘贴到"J6"中

5.Paste it in "J6"

使用此:

'1. Variant with copy method
     Sub test()
        On Error Resume Next
        If [J5].Value <> "" Then
            Columns("D:D").Find([J5].Value).Offset(, 1).Copy [J6]
        Else
            MsgBox "Cell [J5] is empty!"
        End If
        If Err.Number > 0 Then
            MsgBox "Column [D] does not contain search criteria: " & [J5].Value
            Err.Clear
        End If
    End Sub

'2. Variant without copy method
    Sub test2()
        On Error Resume Next
        If [J5].Value <> "" Then
            [J6].Value = Columns("D:D").Find([J5].Value).Offset(, 1).Value
        Else
            MsgBox "Cell [J5] is empty!"
        End If
        If Err.Number > 0 Then
            MsgBox "Column [D] does not contain search criteria: " & [J5].Value
            Err.Clear
        End If
    End Sub

这篇关于选择列并从其他单元格中找到值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆