大家好我需要有選擇地將sheet1中的整個行復制到其他工作表。截至目前,我正在使用複選框來選擇行,然後將選定的行復制到用戶選擇的表格中。但是我面臨着一個奇怪的錯誤。有一段時間,代碼運行良好,將精確的數據複製到表單中,但過了一段時間後,它從無處複製錯誤的值。你能幫我解決這個問題嗎?粘貼我正在使用的代碼。將選擇行從Sheet1複製到Sheet2
Sub Addcheckboxes()
Dim cell, LRow As Single
Dim chkbx As CheckBox
Dim MyLeft, MyTop, MyHeight, MyWidth As Double
Application.ScreenUpdating = False
LRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For cell = 2 To LRow
If Cells(cell, "A").Value <> "" Then
MyLeft = Cells(cell, "E").Left
MyTop = Cells(cell, "E").Top
MyHeight = Cells(cell, "E").Height
MyWidth = Cells(cell, "E").Width
ActiveSheet.CheckBoxes.Add(MyLeft, MyTop, MyWidth, MyHeight).Select
With Selection
.Caption = ""
.Value = xlOff
.Display3DShading = False
End With
End If
Next cell
Application.ScreenUpdating = True
End Sub
Sub RemoveCheckboxes()
Dim chkbx As CheckBox
For Each chkbx In ActiveSheet.CheckBoxes
chkbx.Delete
Next
End Sub
Sub CopyRows()
Dim Val As String
Val = InputBox(Prompt:="Sheet name please.", _
Title:="ENTER SHEET NAME", Default:="Sheet Name here")
For Each chkbx In ActiveSheet.CheckBoxes
If chkbx.Value = 1 Then
For r = 1 To Rows.Count
If Cells(r, 1).Top = chkbx.Top Then
With Worksheets(Val)
LRow = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & LRow & ":AF" & LRow) = _
Worksheets("Usable_Inv_Data").Range("A" & r & ":AF" & r).Value
End With
Exit For
End If
Next r
End If
Next
End Sub
普通複印輸出:
錯誤複印輸出,用於相同的價值觀:
謝謝你的評論。這是問題,但我該如何自動化?爲什麼它首先發生?最初的一兩次一切都很順利,但突然之後,格式發生了變化,這是非常奇怪的 –
它在修改過的代碼的第4行顯示如下錯誤:http://postimg.org/image/fgobg51c1/ –
我可以假設你沒有明白錯誤了,因爲你接受了我的答案,或者你仍然看到它嗎? – Jaycal