I have an excel Macro that I've "Inherited" I'm not very familiar with VBA so the exact specifics of figuring out what is wrong with this code has become a slight problem, There's a Column (Column F) in a Table that has a Comments section. This comment section is suppose to be persistent through the data refreshes being performed. (If I add a comment to an entry despite the data source's comment section being empty it should keep the comments I added previously) According to my Supervisor this used to work but in the past 6 months has stopped working and I believe it may've been due to a bad edit or modification of the macro
I've already edited the code to work with my new Data Connection, and I've corrected it some to properly handle the data now but this comment function is missing and I can tell there is a section of the code that handles the column and section but I can't tell what's wrong with it.
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
My Expected Result is that the Table Column: "Comments" (Which is column F) keeps whatever is entered into it despite the information pulled from the data source on our SharePoint.
So, If on my SharePoint the Comment cell it has "ID-0001" but in my Excel file it has the Comment - "Needs Approval" when the data is refreshed via the Macro it should somehow keep the "Needs Approval" comment that is in the file. Appending the File's Comment to the SharePoint Data's comment. (Even if they're blank it should still keep the File's comment).
If any more clarification is needed I'll do my best to Provide it.