消息框不工作的方式应该和循环复制数据

  • 有没有更简单的方法来做到这一点?
  • 就像在一次点击和数据去我想要的地方?
  • 或者也许这个更短的代码?

由于工作表可能会有所不同,但细节都是一样的..请参阅转让表2和3中的差异…

C列中的某些单元格可能是空白的(指的是我从哪里复制),但我想复制它,以便每行的细节不会混乱。 可以这样做吗? 即使它有一个空的单元格复制?

另外,我的第二个和第三个循环的东西是错误的…第二个,当我点击一次,没关系,但如果意外,你再次点击它的数据将重复..有没有办法阻止这种重复发生?

我尝试使用一个消息框,但它不工作的方式,我希望它是..我希望消息框,只有当我第二次点击它…我想这是因为我用的偏移量…但我真的不知道。

Sub TransferSheet1() Dim i As Long Dim LastRow As Long Dim wb As Workbook Dim sec As Worksheet Dim sht1 As Worksheet Set wb = ThisWorkbook Set sec = wb.Sheets("SECOND") Set sht1 = wb.Sheets("Sheet1") 'Find the last row (in column c) with data. LastRow = sht1.Range("C:C").Find("*", searchdirection:=xlPrevious).row ii = 2 'This is the beginning of the loop For i = 6 To LastRow 'First activity sec.Range("A" & ii) = sht1.Range("C" & i).Value sec.Range("B" & ii) = sht1.Range("D" & i).Value sec.Range("C" & ii) = sht1.Range("F" & i).Value sec.Range("D" & ii) = sht1.Range("G" & i).Value ii = ii + 1 Next i End Sub Private Sub GetValuesFromSheet2() Dim i As Long Dim ii As Long Dim LastRow As Long Dim wb As Workbook Dim sec As Worksheet Dim sht2 As Worksheet Set wb = ThisWorkbook Set sec = wb.Sheets("SECOND") Set sht2 = wb.Sheets("Sheet2") 'Find the last row (in column c) with data. LastRow = sht2.Range("C:C").Find("*", searchdirection:=xlPrevious).row ii = 1 'This is the beginning of the loop For i = 6 To LastRow 'First activity sec.Range("A" & Rows.count).End(xlUp).Offset(1) = sht2.Range("C" & i).Value sec.Range("B" & Rows.count).End(xlUp).Offset(1) = sht2.Range("D" & i).Value sec.Range("C" & Rows.count).End(xlUp).Offset(1) = sht2.Range("F" & i).Value sec.Range("D" & Rows.count).End(xlUp).Offset(ii, 1) = sht2.Range("G" & i).Value ii = ii + 1 Next i With Application .EnableEvents = True .DisplayAlerts = True End With MsgBox "Content Already copied" End Sub Private Sub CmdTransferSheet3_Click() Dim i As Long Dim ii As Long Dim LastRow As Long Dim wb As Workbook Dim sec As Worksheet Dim sht2 As Worksheet Set wb = ThisWorkbook Set sec = wb.Sheets("SECOND") Set sht2 = wb.Sheets("Sheet3") 'Find the last row (in column c) with data. LastRow = sht2.Range("C:C").Find("*", searchdirection:=xlPrevious).row ii = 1 'This is the beginning of the loop For i = 6 To LastRow 'First activity sec.Range("A" & Rows.count).End(xlUp).Offset(1) = sht2.Range("C" & i).Value sec.Range("B" & Rows.count).End(xlUp).Offset(1) = sht2.Range("D" & i).Value sec.Range("C" & Rows.count).End(xlUp).Offset(1) = sht2.Range("F" & i).Value sec.Range("E" & Rows.count).End(xlUp).Offset(ii,1) = sht2.Range("G" & i).Value ii = ii + 1 Next i End Sub