有没有一种方法可以在数据源中的单元格数据上替换/附加单元格数据

时间:2019-08-21 19:49:59

标签: excel vba sharepoint

我有一个“继承”的excel宏我对VBA不太熟悉,因此弄清楚此代码出了什么问题的确切细节已成为一个小问题,其中有一个列(列F)具有注释部分的表。假定此注释部分在正在执行的数据刷新中保持不变。 (如果尽管数据源的注释部分为空,但我仍在条目中添加注释,则应保留我之前添加的注释。)根据我的主管的说法,此方法过去一直有效,但在过去的6个月中已停止工作,我相信它可能已经是由于宏的修改或修改错误

我已经编辑了与新数据连接一起使用的代码,并且我已经对其进行了更正,以现在可以正确处理数据,但是缺少此注释功能,我可以确定其中有一部分代码可以处理专栏和专栏,但我不知道这是怎么回事。

Sub RefreshAndDelete()
'
'
'
'

    Dim sht as Sheets
    Dim rng as Range
    Dim col as Columns
    Dim row as Rows
    Application.ScreenUpdating = False
    Set sht = Sheets("Ready Board")
    sht.Visible = True
    sht.Cells.Select
    If (sht.AutoFilterMode And sht.FilterMode) or sht.FilterMode Then
    sht.ShowAllData
    End If
    set col = Columns("A:F")
    set rng = Range("IE_Testing_Board[[#Headers],[Comments]]")
    col.Copy
    Sheets.Add, Worksheets(Worksheets.Count)
    ActiveSheet.Name = "Raw Data"
    ActivateSheet.Paste
    Selection.NumberFormat = "General"
    set col = Columns("A:A")
    Application.CutCopyMode = False
    col.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    set rng = Range("A2")
    rng.FormulaR1C1 = "=RC[4]&RC[3]&RC[2]"
    rng.Offset(0, 1).Select
    rng.End(xlDown).Select
    rng.Offset(0,-1).Select
    set rng =  Range(Selection, Selection.End(xlUp))
    rng.FillDown
    set rng = Range("F1")
    set rng = rng.Offset(1,0)
    Selection.Offset(1, 0).Select
    ActiveCell.Offset(0, -2).Select
    set rng = Range(Selection, Selection.End(xlDown))
    rng.Offset(0,2)
    rng.ClearContents
    ActiveWorkbook.RefreshAll
    sht.ListObjectsListObjects("IE_Testing_Board").Range.AutoFilter field:=11, Criteria1:="Yes"
    If Criteria1 <> "" Then
    set row = Rows("1:1")
    row.Offset(1,0)
    set rng = Range(Selection, Selection.End(xlDown))
    rng.EntireRow.RefreshAndDelete
    sht.ListObjects("IE_Testing_Board").Range.AutoFilter field:=11
    Else
    sht..ListObjects("IE_Testing_Board").Range.AutoFilter field:=11
    End If
    set rng = Range("F1").Offset(1,0)
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP([@[Part '#]]&[@[Operation '#]]&[@[Machine '#]],'Raw Data'!C[-5]:C[1],7,FALSE),"""")"
    set rng = Range("E1").Offset(1,0)
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP([@[Part '#]]&[@[Operation '#]]&[@[Machine '#]],'Raw Data'!C[-4]:C[1],6,FALSE),"""")"
    set rng = Range("F2")
    rng.AutoFill Destination:=Range("IE_Testing_Board[Comments]")
    sht.ListObjects("IE_Testing_Board").Range.AutoFilter field:=6, _
        Criteria1:="0"
    set rng = Range("F1").Offset(1,0)
    set rng = Range(rng, rng.End(xlDown))
    rng.ClearContents
    sht.ListObjects("IE_Testing_Board").Range.AutoFilter field:=6
    set rng = Range("E2")
    rng.AutoFill Destination:=Range("IE_Testing_Board[Part Program]")
    sht.ListObjects("IE_Testing_Board").Range.AutoFilter field:=5, _
        Criteria1:="0"
    set rng = Range("E1").Offset(1,0)
    set rng = Range(rng, rng.End(xlDown))
    rng.ClearContents
    sht.ListObjects("IE_Testing_Board").Range.AutoFilter field:=5
    set rng = Range("IE_Testing_Board[Comments]")
    rng.Copy
    set rng = Range("F2")
    rng.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    set rng = Range("IE_Testing_Board[Part Program]")
    rng.Copy
    set rng = Range("E2")
    rng.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    set rng = Range("E2")
    sht.Visible = False
    set sht = Sheets("Raw Data")
    Application.DisplayAlerts = False
    sht.Delete
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    set sht = Sheets("Home")

End Sub

我的预期结果是,尽管从SharePoint上的数据源中提取了信息,但表列:“注释”(其中F列)保留了输入的内容。

因此,如果在我的SharePoint上,注释单元格具有“ ID-0001”,但在我的Excel文件中,其注释具有“需要批准”,则当通过宏刷新数据时,它应该以某种方式保持“需要批准”文件中的注释。将文件的注释附加到SharePoint数据的注释。 (即使它们为空,也应保留文件的注释。)

如果需要更多说明,我会尽力提供。

0 个答案:

没有答案