将粘贴数据复制到另一个工作簿中的一行,每次保存时更新列

发布于 2025-02-07 17:28:17 字数 3019 浏览 3 评论 0原文

我正在尝试将一排从一个工作簿复制到另一个工作簿。有3列将在不同的日期上更新,每次我想将其保存到目的地时,都不会替换行,而是将其转到另一行。我希望代码每次粘贴时都会替换现有数据。我想避免粘贴现有列或对其进行更新,以便结果在一行中。

 Else
    dstn = "S:\Radiotherapy-Department\Brachytherapy\Spreadsheets\Developement\Josmi_Project _ DB\Postsource exchangeResults.xlsx"
    Workbooks.Open (dstn)
    Sheets("Result-1").Activate
    ActiveSheet.Unprotect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Range("M11:M12").Copy
    lastRow = Sheets("Result-1").Cells(Rows.Count, "A").End(xlUp).Row + 1
    Cells(lastRow, 1).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    ActiveSheet.Protect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Activate
End If
 
If Range("N11") = "" Then
    MsgBox "Confirm 'Pre & 1st Post'source exchange RAKR measurement completed"
Else
    dstn = "S:\Radiotherapy-Department\Brachytherapy\Spreadsheets\Developement\Josmi_Project _ DB\Postsource exchangeResults.xlsx"
    Workbooks.Open (dstn)
    Sheets("Result-1").Activate
    ActiveSheet.Unprotect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Range("N11:N12").Copy
    lastRow = Sheets("Result-1").Cells(Rows.Count, "C").End(xlUp).Row + 1
    Cells(lastRow, 3).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    ActiveSheet.Protect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Activate
End If
    
If Range("O11") = "" Then
    MsgBox "Confirm 'Pre & Post'source exchange RAKR measurement completed"
Else
    dstn = "S:\Radiotherapy-Department\Brachytherapy\Spreadsheets\Developement\Josmi_Project _ DB\Postsource exchangeResults.xlsx"
    Workbooks.Open (dstn)
    Sheets("Result-1").Activate
    ActiveSheet.Unprotect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Range("O11:O12").Copy
    lastRow = Sheets("Result-1").Cells(Rows.Count, "E").End(xlUp).Row + 1
    Cells(lastRow, 5).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    ActiveSheet.Protect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Activate
End If
    
If Range("P11") = "" Then
    MsgBox "Confirm 'Pre & Post'source exchange RAKR measurement completed"
Else
    dstn = "S:\Radiotherapy-Department\Brachytherapy\Spreadsheets\Developement\Josmi_Project _ DB\Postsource exchangeResults.xlsx"
    Workbooks.Open (dstn)
    Sheets("Result-1").Activate
    ActiveSheet.Unprotect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Range("P11:P12").Copy
    lastRow = Sheets("Result-1").Cells(Rows.Count, "G").End(xlUp).Row + 1
    Cells(lastRow, 7).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    ActiveSheet.Protect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Activate
    ActiveSheet.Unprotect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Range("M11:P12").ClearContents
    MsgBox "SOURCE STRENGTH VERIFICATION RESULTS SAVED SUCCESSFULLY"
    ActiveSheet.Protect
End If

初始表

这是第一个表。抱歉

保存第二次后

”在此处输入图像描述

I'm trying to copy paste a row from one workbook to another. There are 3 columns which will be updated on different dates, and each time I want to save it to destination it is not replacing the row, instead it is going to another row. I want code to replace the existing data every time I paste.I want to avoid pasting the existing column or update it so that the results are in one row.

 Else
    dstn = "S:\Radiotherapy-Department\Brachytherapy\Spreadsheets\Developement\Josmi_Project _ DB\Postsource exchangeResults.xlsx"
    Workbooks.Open (dstn)
    Sheets("Result-1").Activate
    ActiveSheet.Unprotect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Range("M11:M12").Copy
    lastRow = Sheets("Result-1").Cells(Rows.Count, "A").End(xlUp).Row + 1
    Cells(lastRow, 1).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    ActiveSheet.Protect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Activate
End If
 
If Range("N11") = "" Then
    MsgBox "Confirm 'Pre & 1st Post'source exchange RAKR measurement completed"
Else
    dstn = "S:\Radiotherapy-Department\Brachytherapy\Spreadsheets\Developement\Josmi_Project _ DB\Postsource exchangeResults.xlsx"
    Workbooks.Open (dstn)
    Sheets("Result-1").Activate
    ActiveSheet.Unprotect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Range("N11:N12").Copy
    lastRow = Sheets("Result-1").Cells(Rows.Count, "C").End(xlUp).Row + 1
    Cells(lastRow, 3).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    ActiveSheet.Protect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Activate
End If
    
If Range("O11") = "" Then
    MsgBox "Confirm 'Pre & Post'source exchange RAKR measurement completed"
Else
    dstn = "S:\Radiotherapy-Department\Brachytherapy\Spreadsheets\Developement\Josmi_Project _ DB\Postsource exchangeResults.xlsx"
    Workbooks.Open (dstn)
    Sheets("Result-1").Activate
    ActiveSheet.Unprotect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Range("O11:O12").Copy
    lastRow = Sheets("Result-1").Cells(Rows.Count, "E").End(xlUp).Row + 1
    Cells(lastRow, 5).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    ActiveSheet.Protect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Activate
End If
    
If Range("P11") = "" Then
    MsgBox "Confirm 'Pre & Post'source exchange RAKR measurement completed"
Else
    dstn = "S:\Radiotherapy-Department\Brachytherapy\Spreadsheets\Developement\Josmi_Project _ DB\Postsource exchangeResults.xlsx"
    Workbooks.Open (dstn)
    Sheets("Result-1").Activate
    ActiveSheet.Unprotect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Range("P11:P12").Copy
    lastRow = Sheets("Result-1").Cells(Rows.Count, "G").End(xlUp).Row + 1
    Cells(lastRow, 7).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    ActiveSheet.Protect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Activate
    ActiveSheet.Unprotect
    ThisWorkbook.Sheets("FORM.HDR 1.1").Range("M11:P12").ClearContents
    MsgBox "SOURCE STRENGTH VERIFICATION RESULTS SAVED SUCCESSFULLY"
    ActiveSheet.Protect
End If

Initial Table

this is the first table. sorry

Result after saving the second time

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文