Excel 我的粘贴功能不起作用,我不知道为什么
我正在尝试将我从主列表中选择的条目表单复制到其他工作表中。这个想法是,它会在一个没有细节的精简名单中出现。看看我选择了什么。复制选定的条目表单并将其粘贴到新位置,以生成仅包含我需要的条目表单的列表。我无法判断循环是否正常工作,因为最后的粘贴函数不工作Excel 我的粘贴功能不起作用,我不知道为什么,excel,vba,Excel,Vba,我正在尝试将我从主列表中选择的条目表单复制到其他工作表中。这个想法是,它会在一个没有细节的精简名单中出现。看看我选择了什么。复制选定的条目表单并将其粘贴到新位置,以生成仅包含我需要的条目表单的列表。我无法判断循环是否正常工作,因为最后的粘贴函数不工作 Sub BidList() 'Sets unique terms used throught this code Dim wQuick As Worksheet, wMaster As Worksheet Dim BlankFou
Sub BidList()
'Sets unique terms used throught this code
Dim wQuick As Worksheet, wMaster As Worksheet
Dim BlankFound As Boolean
Dim x As Long, n As Long, y As Long
Dim firstrow As Long, pasterow As Long, lastrow As Long, PasteCell As String, MyRange As String
'Turns off Screen updating to save memory
Application.ScreenUpdating = False
'Store an initial value for "x" effectively starting the macro at C4 after the +1 in the next step
x = 3
n = 0
y = 0
Set wQuick = ThisWorkbook.Sheets("Quick Reference")
Set wMaster = ThisWorkbook.Sheets("MASTER")
BlankFound = False
'Loop until x equals 600
Do While BlankFound = False
x = x + 1
n = n + 1
If Trim(wQuick.Cells(x, "B").Value) = "" Then Exit Do
'If there is a 1 in the Boolean column then ...
If Trim(wQuick.Cells(x, "C").Value) = "1" Then
'Move the y value so that the template is pasted in the appropriate place
y = y + 1
'Copy the appropriate form from wMaster
firstrow = (n * 9) + 18
lastrow = (n * 9) + 27
Let MyRange = "A" & firstrow & ":" & "K" & lastrow
wMaster.Range(MyRange).Copy
'Select the next place for the form to be pasted on wQuick
pasterow = (y * 9) - 5
Let PasteCell = "F" & "," & pasterow
wQuick.Cells(PasteCell).Paste
End If
Loop
Application.ScreenUpdating = True
End Sub
请避免在Excel中复制粘贴,最好使用for循环,如下所示:
# keep track of MyRange.Row and MyRange.Column
For Each cell in wMaster.Range(MyRange):
wQuick.Cells(<Starting point>).Offset(<take the cell coordinates, based on MyRange.Row and/or MyRange.Column>).Value = cell.Value
Next
顺便说一句,最好不要使用范围对象,而不是它们的地址,但那一行可以是wQuick.RangeF&pasterrow.Paste。单元格需要两个参数,而不是一个带逗号的字符串参数。谢谢。我成功了请避免在Excel中复制粘贴您是针对这个特定场景还是一般情况说的?我无法使用该方法,因为我需要它将输入表单粘贴到下一个可用空间,并且我的输入表单有9行高,但我确实成功了。不幸的是,它仍然使用复制和粘贴。我感谢你抽出时间来帮忙。