【问题标题】:Transferring Data Between Sheets (Excel VBA)在工作表之间传输数据 (Excel VBA)
【发布时间】:2016-07-21 10:55:00
【问题描述】:

所以我试图在一个“主”表和多个“子”表之间进行复杂的数据传输。今天是我使用 Excel VBA 的第一天,所以我很迷茫哈哈。我决定从小处着手,将数据从一张纸的一个单元格传输到另一张纸,但我不断收到“无法跳转到'表格',因为它是隐藏的”的错误。谁能帮我一把?提前致谢。

Sub transfer()
Dim strSourceSheet As String, strDestinationSheet As String, sourceData As String
strSourceSheet = "profile list"
Sheets(strSourceSheet).Activate
sourceData = Sheets(strSourceSheet).Cells(30, 37).Value
strDestinationSheet = "RADIANT OPTO-ELECTRONICS CORP."
Sheets(strDestinationSheet).Activate
Sheets(strDestinationSheet).Cells(C, 11) = sourceData
End Sub

【问题讨论】:

  • 问题已解决!
  • 发布您的解决方案。

标签: vba excel


【解决方案1】:

您很少需要激活工作表或范围。你应该视频Selecting Cells (Range, Cells, Activecell, End, Offset)Worksheets, Charts and Sheets

Sub transfer()
    Const strDestinationSheet As String = "RADIANT OPTO-ELECTRONICS CORP."
    Const strSourceSheet As String = "profile list"

    Sheets(strDestinationSheet).Cells(C, 11) = Sheets(strSourceSheet).Cells(30, 37).Value
End Sub

【讨论】:

    【解决方案2】:

    如果您的Sheet(strSourceSheet)被隐​​藏,则无法激活,需要先取消隐藏。

    如果工作表已隐藏,请使用以下 if 取消隐藏工作表:

    ' The sheet is hidden then unhide it
    If ThisWorkbook.Worksheets(strSourceSheet).Visible = False Then ' Check if one is visable.
        ThisWorkbook.Worksheets(strSourceSheet).Visible = True
    End If
    

    第二张表也是如此Sheets(strDestinationSheet)

    不过,话虽如此,如果你只想在工作表之间复制单元格,最好避免SelectActivate,你所要做的就是:

    'However, having said that, if all you want is to copy cells betwwen sheets all you have to do is :
    
    Sub transfer()
    
    Dim strSourceSheet As String, strDestinationSheet As String, sourceData As String
    
    strSourceSheet = "profile list"
    strDestinationSheet = "RADIANT OPTO-ELECTRONICS CORP."
    
    ' this is how you referrence Cell(C11), if that's what you meant
    Sheets(strDestinationSheet).Cells(11, "C") = Sheets(strSourceSheet).Cells(30, 37).Value
    
    End Sub
    

    【讨论】:

    • 谢谢!这很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    相关资源
    最近更新 更多