【问题标题】:To remove Shift xlUp or Down from the code从代码中删除 Shift xlUp 或 Down
【发布时间】:2020-06-21 14:24:52
【问题描述】:

此代码是在其中一个线程上找到的。 与代码相关的一切都很有用,除了一个 也就是说,在执行代码之后,数据是 向上移动。我想要那一行,即 A 到 F 应该 变为空白,数据不向上移动。试着 从代码中删除 Shift:=xlShiftUp 但数据仍然是 在源文件 (Sheet1) 中向上移动。 代码是

私有子命令按钮1_Click() 调暗源作为范围,目标作为范围

With Worksheets("Sheet1")
    Set Source = .Range("A3", .Range("A" & .Rows.Count).End(xlUp))
End With

Set Target = Source.Find(What:=DCNameTextBox1.Value, LookIn:=xlValues, LookAt:=xlWhole)
    
If Not Target Is Nothing Then
    'Reference the next enmpty row on Sheet2
    With Worksheets("Sheet2")
        With .Range("A" & .Rows.Count).End(xlUp).Offset(1)
            '.Range("A1:F1") is relative to the row of it's parent range
            .Range("A1:F1").Value = Target.Range("A1:F1").Value
            .Range("H1:J1").Value = Array(DCDateTextBox.Value, DispoTextBox.Value, ReasonTextBox.Value)

            Set Source = .Range("A3", .Range("A" & .Rows.Count).End(xlUp))
        End With
    End With
    Target.Range("A1:F1").Delete Shift:=xlShiftUp
    
    MsgBox "Client has been moved to Discharge list."
Else
    MsgBox "Client not found", vbInformation, "No Data"
End If

Range("A3").Select

结束子

【问题讨论】:

    标签: shift


    【解决方案1】:

    不确定我是否完全理解,但是如果您想清除 A1:F1 的内容,请执行

    Target.Range("A1:F1").ClearContents
    

    而不是

    Target.Range("A1:F1").Delete Shift:=xlShiftUp
    

    如果没有F1的权利,那你可以做

    Target.Range("A1:F1").Delete Shift:=xlToLeft
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-10
      • 1970-01-01
      • 2013-02-11
      • 2012-09-29
      • 1970-01-01
      相关资源
      最近更新 更多