如何解决计算行单元格并复制并粘贴
我使用我的代码处理基于C#的宏软件 但是我只想使用VBA而不是c#来执行宏 能做到吗?不使用点?
- B2〜Bxxxxx中的数据
- 我的c#程序确实复制了B2单元格值并粘贴了另一个工作表K3单元格
- 在代码下运行宏
Sub CopyRows()
Application.ScreenUpdating = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Dim bottomL As Long
Dim x As Long
bottomL = Sheets("Total").Range("L" & Rows.Count).End(xlUp).Row: x = 1
Dim c As Range
Dim lr As Long
lr = Cells(Rows.Count,1).End(xlUp).Row
For Each c In Sheets("Total").Range("K1:K" & bottomL)
If c.Value = "Inside" Then
c.EntireRow.Copy Worksheets("filter").Range("A" & Rows.Count).End(xlUp).Offset(1,0)
x = x + 1
End If
Next c
End Sub
- 然后我的c#程序确实选择b3并复制到其他工作表k3单元格,然后运行宏,然后循环该过程并结束Bxxxxx上的单元格
有人知道只能使用VBA吗?
对不起,我的英语不好
解决方法
在VBA中输入完整的代码,如下所示:
Function CopyRows()
Application.ScreenUpdating = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Dim bottomL As Long
Dim x As Long
bottomL = Sheets("Total").Range("L" & Rows.Count).End(xlUp).Row
x = 1
Dim c As Range Dim lr As Long
lr = Cells(Rows.Count,1).End(xlUp).Row
For Each c In Sheets("Total").Range("K1:K" & bottomL)
If c.Value = "Inside" Then
c.EntireRow.Copy
Worksheets("filter").Range("A" & Rows.Count).End(xlUp).Offset(1,0)
x = x + 1
End If
Next c
End Function
Sub Main()
Dim bottomB As Long
Dim y As Long
bottomB = Range("B" & Rows.Count).End(xlUp).Row
For y = 2 To bottomB
Range("B" & 2).Copy Worksheets("Total").Range("K3")
CopyRows
Next
End Sub
然后仅运行Sub Main()。
,感谢Wasif Hasan
我已经使用了我编写的这段代码
Sub dual()
Application.ScreenUpdating = False ActiveSheet.DisplayPageBreaks = False
Dim i As Long
Dim totalRows As Long
Dim lastRow As Long
Dim Number As Long
Dim nowRows As Long
Dim bottomL As Long
Dim x As Long
Dim c As Range
Dim lr As Long
bottomL = Sheets("Total").Range("L" & Rows.Count).End(xlUp).Row: x = 1
lr = Cells(Rows.Count,1).End(xlUp).Row
With Worksheets("List")
'for looping
totalRows = .Cells(.Rows.Count,"B").End(xlUp).Row
'index of row to add from
lastRow = totalRows + 1 '<--| start pasting values one row below the last non empty one in column "B"
'data starts at row #2
For i = 2 To totalRows
If .Cells(i,2).Value > 0 Then
Worksheets("List").Cells(i,"B").Copy
Worksheets("Total").Range("K3").PasteSpecial Paste:=xlPasteValues
lastRow = lastRow + Number
For Each c In Sheets("Total").Range("L1:L" & bottomL)
If c.Value = "Inside" Then
c.EntireRow.Copy Worksheets("filter").Range("A" & Rows.Count).End(xlUp).Offset(1,0)
x = x + 1
End If
Next c
End If
Next i
End With Application.ScreenUpdating = True ActiveSheet.DisplayPageBreaks = True End Sub
,但在复制和粘贴时丢失了许多数据 所以需要等待粘贴完成 所以我用其他程序 有什么办法让等待粘贴完成吗? 想你的答案
,如果没有必要复制和粘贴,请尝试不使用该命令。仅使用cell1.Value = cell2.Value更快。 在您的情况下,您应该声明一个变量以计算b中的列总数。然后使用循环遍历b2直至bx。 示例:
将i视作整数
dim j为Integer
j = 3
对于i = 2等于totalCount
Worksheet.Cells(2,i).Value = Worksheet2.Cells(11,j)
j = j + 1
下一个我
在上面2 = B列和11 = K列
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。