我有一个 Excel 数据集。从 C 列开始,它具有从 C2 到每次使用时都会更改的可变数字的连续数据 对于 D 列中的每一行连续数据,我也想选择 C-J 列的行。我正在尝试选择此数据以使用该数据创建一个新的 Excel。
我收集来构建我希望创建的代码似乎不起作用。
Dim lastVal As Range, sht As Worksheet
Set sht = Sheets("sheet1")
Set lastVal = sht.Columns(4).Find("*", sht.Cells(1, 48), xlValues, _
xlPart, xlByColumns, xlPrevious)
Debug.Print lastVal.Address
sht.Range("C2", lastVal).Resize(, 48).Select
selection.copy
Set Objexcel = CreateObject("Excel.application")
objexcel.visible = True
objexcel.cells(1, 1).paste
类似这样的:
Sub Tester()
Dim sht As Worksheet, wb As Workbook
Set sht = ThisWorkbook.Sheets("sheet1") 'or activeworkbook
Set wb = Workbooks.Add() 'add new workbook
'copy from Col C, using last row from Col D?
'not sure if that's really what you want though?
With sht.Range("C2:C" & sht.Cells(Rows.Count, 4).End(xlUp).Row)
Debug.Print "copying", .Address
.Copy wb.Worksheets(1).Range("A1")
End With
End Sub