vba 将sheet1中一列单元格部分数据复制 粘贴至新建的sheet2
想使用vba实现一下功能在excel表sheet1中,先通过文本框输入编号信息检索,然后将所在行的第1,2,5,9列的信息分别复制到新建的sheet2中的1,2,3,4列中。
重复上述操作时,sheet2中的信息需要按搜索顺序排列汇总
有点复杂,望各位不吝赐教,小弟不胜感激。
Dim newSheet As Worksheet On Error Resume Next Set newSheet = Worksheets("新建表") If TypeName(newSheet) = "Worksheet" Then newSheet.UsedRange.ClearContents Else Set newSheet = Worksheets.Add newSheet.Name = "新建表" End If On Error GoTo 0 Dim sh1 As Worksheet Set sh1 = Worksheets("Sheet1") sh1.UsedRange.ClearContents sh1.Columns(1).Resize(10, 1).Value = 1 sh1.Columns(2).Resize(10, 1).Value = 2 sh1.Columns(5).Resize(10, 1).Value = 5 sh1.Columns(9).Resize(10, 1).Value = 9 Dim rng As Range ' Set rng = Union(sh1.Columns(1).Resize(10, 1), _ ' sh1.Columns(2).Resize(10, 1), _ ' sh1.Columns(5).Resize(10, 1), _ ' sh1.Columns(9).Resize(10, 1)) Set rng = Union(sh1.Columns(1), sh1.Columns(2), sh1.Columns(5), sh1.Columns(9)) rng.Copy newSheet.Cells(1, 1)
[此贴子已经被作者于2022-1-17 11:09编辑过]