我有我有命令按鈕和輸入文本框的用戶窗體。複製範圍到另一個工作表,並從輸入框中插入名稱與此副本
我想從一張工作表中複製指定範圍,然後命名並粘貼到另一張工作表中。 我的代碼看起來像這樣,但它不起作用。
Private Sub CommandButton1_Click()
Dim i, LastRow
Dim ws As Worksheet
Dim k As Integer
Set ws = Worksheets("Vali")
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For i = 4 To LastRow 'find fulfiled rows
If Sheets("Sheet1").Cells(i, "D").Value = 1 Then
Sheets("Sheet1").Range(Cells(i, "B"), Cells(i, "D")).Copy Destination:=Sheets("Vali").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
Dim i As Integer
'Next we use a looping process 'We start the loop from row 2 because our worksheet has headers in row 1
For k = 2 To 100
'Now we define a condition that only if there is data under the headers ItemID, Description,
If Cells(k, "A").Value <> "" And Cells(k, "B").Value <> "" And Cells(k, "C").Value <> "" And Cells(k, "D").Value <> "" And Cells(k, "E").Value = "" Then
Cells(k, "D").Value = Me.txtname.Value
End If
Next
Range("E:E").EntireColumn.AutoFit
Range("B4:D21").ClearContents 'clear content on previos sheet, from where we made copy
ActiveWorkbook.Save
ValiFinish.Hide
End Sub
PLZ使用{}圖標以可讀的方式重新排列代碼。當錯誤提示時它說什麼?並在哪一行? – R3uK 2015-04-02 13:07:35
謝謝,我無法理解,有些時候它說無效使用了Me關鍵字,但有時它以某種方式使其動作,但沒有數據輸入到E列中。還有關於如果沒有阻止的話。我認爲IF條件不是故意的。請考慮命令按鈕在工作表1上。 – 2015-04-02 19:51:13
命令按鈕僅從一張紙複製到另一張,但當我在輸入框中輸入名稱時,名稱未插入。 – 2015-04-03 07:30:24