问题描述
试图教我自己VBA,这是非常新的。到目前为止,Stackoverflow一直是一个非常棒的资源,所以我想我会问这个。我想要做的是找到名为Reference的单元格,然后复制下面的列。
由于某种原因,我无法在网上找到任何内容,并且认为我会咬住子弹并提交问题。
谢谢。
这取决于cell named的含义。如果单元实际上命名为参考(即如果您将单元格 A1
的范围重命名为参考
您可以使用偏移方法复制下面的单元格:
ActiveSheet.Range(Reference)。Offset(1 ,0).Copy
如果您正在搜索具有值参考的单元格,您可以找到这个单元格并复制单元格,使用这样的方法(请注意,如果有多个单元格符合搜索条件,它会将单元格复制到最后找到的单元格下方):
使用ActiveSheet.UsedRange
设置c = .Find(参考,LookIn:= xlValues)
如果不是c是没有,然后
ActiveSheet.Range(c.Address).Offset(1,0).Copy
End If
End With
如果要将整个列复制到特定单元格下方,可以按照以下代码执行某些操作:在这种情况下,它将复制以下所有已使用的单元格e细胞 C7
。
Sub CopyColumnBelow()
Dim r As Range
设置r = ActiveSheet.Range(C7)
ActiveSheet.Range(r,ActiveSheet.Cells(Rows.Count,r.Column).End(xlUp)。地址).Copy
End Sub
希望你可以用它来推动学习Excel VBA 。
Trying to teach myself VBA and am very new to this. Stackoverflow has been an awesome resource so far so I figured I'd ask it here.
What I want it to do is find the cell named "Reference," then copy the column below it.
For some reason I can't find this anywhere online and figured I'd bite the bullet and submit a question.
Thanks.
It depends on what you mean by "cell named". If the cell is in fact named "Reference" (i.e. if you have renamed the range of cell A1
to Reference
, you can then copy the cell below this by using the offset method:
ActiveSheet.Range("Reference").Offset(1, 0).Copy
If you instead are searching for a cell with the value "Reference" you can find this cell and copy the cell blow this by using a method like this (note that if there are multiple cells that meet the search criteria, it will copy the cell below the last found cell):
With ActiveSheet.UsedRange
Set c = .Find("Reference", LookIn:=xlValues)
If Not c Is Nothing Then
ActiveSheet.Range(c.Address).Offset(1, 0).Copy
End If
End With
If you want to copy an entire column below a specific cell, you can do something in line of the following code. In this case it will copy all of used cells below the cell C7
.
Sub CopyColumnBelow()
Dim r As Range
Set r = ActiveSheet.Range("C7")
ActiveSheet.Range(r, ActiveSheet.Cells(Rows.Count, r.Column).End(xlUp).Address).Copy
End Sub
Hope you can use this to move forward learning Excel VBA.
这篇关于搜索标题名称后选择整个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!