我正在嘗試複製特定列中的所有數據,並透過 VBA 將其貼上到工作簿中的另一張工作表中,因為這將在多個列中重複。由於某種原因 - 並非所有資料都會被傳輸,因為有些資料是空白的。我的VBA程式碼如下。
我是VBA新手,謝謝大家的幫忙,謝謝!
wsRawT 和 wsDetI 是我為指定工作表定義的變數。
wsRawT.Select
range("AU1").Select
ActiveCell.Offset(1, 0).range("A1").Select
range(Selection, Selection.End(xlDown)).Select
Selection.copy
wsDetI.Select
range("A1").Select
ActiveCell.Offset(1, 0).range("A1").Select
ActiveSheet.Paste
答案1
Sub test()
Dim wsRawT As Worksheet, wsDetI As Worksheet
Set wsRawT = ThisWorkbook.Sheets("Sheet1")
Set wsDetI = ThisWorkbook.Sheets("Sheet2")
wsRawT.Range(wsRawT.Cells(2, 47), wsRawT.Cells(wsRawT.UsedRange.Rows.Count, 47)).Copy _
Destination:=wsDetI.Cells(2, 1)
End Sub
附言。Range("AU2").Column = 47
答案2
使用者表單可用於列複製。使用者窗體包含兩個列錶框。 Sheet1 上的列標題列在第一個列錶框中。 。使用進階篩選方法將列錶框 2 中選定的列複製到其他工作表 (sheet2)。
Private Sub CommandButton1_Click()
Dim FirstCell, LastCell As Range
Dim basliklar As Integer
Dim baslangic_satiri As Long
Sheets("report").Select
If ListBox2.ListCount = 0 Then
MsgBox "You don't choose filter field "
Exit Sub
End If
ProgressDlg.Show 'Progress Bar
Set LastCell = Sheets("database").Cells(Sheets("database").Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Sheets("database").Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column)
Set FirstCell = Sheets("database").Cells(Sheets("database").Cells.Find(What:="*", After:=LastCell, SearchOrder:=xlRows, _
SearchDirection:=xlNext, LookIn:=xlValues).Row, _
Sheets("database").Cells.Find(What:="*", After:=LastCell, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, LookIn:=xlValues).Column)
For basliklar = 0 To ListBox2.ListCount - 1
baslangic_satiri = 2
Sheets("report").Cells(baslangic_satiri - 1, basliklar + 1) = ListBox2.List(basliklar, 0)
Sheets("database").Range(FirstCell, LastCell).AdvancedFilter _
Action:=xlFilterCopy, CriteriaRange:=Sheets("database").Range(FirstCell, LastCell), _
CopyToRange:=Sheets("report").Cells(baslangic_satiri - 1, basliklar + 1), _
Unique:=False
Next
Sheets("report").Columns.EntireColumn.AutoFit
CommandButton6.Enabled = True
End Sub