[英]To copy values from sheet 1 to sheet 2 and paste it at desired location using vba
My objective is to copy values from cells in sheet 1 "B5" onwards and paste it to sheet 2 "C11" onwards below is the code not working properly 我的目标是从表1“ B5”之前的单元格中复制值并将其粘贴到表2“ C11”之上的下面,因为代码无法正常工作
Sub SCMPROCUREMENT()
' SUPPLY CHAIN MANAGEMENT PROCUREMENT
Worksheets("Sheet1").Select
Range("B5:B100000").Select
finalrow = Cells(Rows.Count, 2).End(xlUp).Row
For x = 5 To finalrow
If Worksheets("sheet1").Cells(x, 2).Font.Bold = False Then
Worksheets("sheet1").Select
Cells(x, 2).Select
Selection.Copy
ThisWorkbook.Worksheets("Sheet2").Range("C11").Select
ActiveSheet.Paste
End If
Next x
End Sub
a) your ThisWorkbook.Worksheets("Sheet2").Range("C11") doesn't work like that a)您的ThisWorkbook.Worksheets(“ Sheet2”)。Range(“ C11”)不能那样工作
b) you need a counter for the second list, otherwise you keep overwriting C11 b)您需要第二个列表的计数器,否则您将覆盖C11
Sub SCMPROCUREMENT()
' SUPPLY CHAIN MANAGEMENT PROCUREMENT
Dim count As Integer
For x = 5 To Worksheets("Sheet1").Cells(Rows.count, 2).End(xlUp).Row
If Worksheets("Sheet1").Cells(x, 2).Font.Bold = False Then
Worksheets("Sheet1").Cells(x, 2).Copy
Worksheets("Sheet2").Cells(11 + count, 3).Select
ActiveSheet.Paste
count = count + 1
End If
Next x
End Sub
Sub SCMPROCUREMENT()
' SUPPLY CHAIN MANAGEMENT PROCUREMENT
Application.ScreenUpdating = False
Dim count As Integer
With Worksheets("Sheet1")
For x = 5 To .Cells(Rows.count, 2).End(xlUp).Row
If .Cells(x, 2).Font.Bold = False Then
.Cells(x, 2).Copy Worksheets("Sheet2").Cells(11 + count, 3)
count = count + 1
End If
Next x
End With
Application.ScreenUpdating = True
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.