In my workbook, I have some cells that sometimes get copied from one place to another. Specifically, it is copying the formulas & values. Sometimes when this happens, I receive a #REF error in a cell that is adding up other cells in the same column, but I can't figure out why.
Here's a screenshot:
I selected "Trace error" and that is why you're seeing the arrows.
In Cell Q53, it has a simple formula: "=N53-L53". The rest of the rows down have the same (=N54-L54, =N55-L55, etc.).
In the formula bar, you can see the formula that is in the cell saying "#REF!"
Values and formulas are being copied into columns N-S right before "#REF!" appears. The code that does the copying is:
FYI: The ColToCopyFrom is not a merged cell. The ColToCopyTo is a merged cell. In this case, ColToCopyTo = "Q".
The code does paste the formulas and values in the proper cells, and I don't ever receive an error when the code runs, so I don't think there is anything wrong with the code. But after it runs is when the "#REF!" error shows up, so I'm guessing it has something to do with it.
The weird thing is, sometimes the above code works fine and doesn't cause the "#REF!" error. But under other conditions, it does. And sometimes, instead of saying "#REF!" it says "#VALUE!"
By the way, I know it's better not to have any merged cells, but I can't remove them because it would mess up the rest of the sheet. So I'm stuck with them.
Any thoughts on what is causing this error?
Here's a screenshot:
I selected "Trace error" and that is why you're seeing the arrows.
In Cell Q53, it has a simple formula: "=N53-L53". The rest of the rows down have the same (=N54-L54, =N55-L55, etc.).
In the formula bar, you can see the formula that is in the cell saying "#REF!"
Values and formulas are being copied into columns N-S right before "#REF!" appears. The code that does the copying is:
VBA Code:
With ThisWorkbook.Sheets("Cost Summary")
.Range(ColToCopyFrom & CS.SummaryLastRow - 6 & ":" & ColToCopyFrom & CS.SummaryLastRow).Copy
.Range(ColToCopyTo & CS.SummaryLastRow - 6 & ":" & ColToCopyTo & CS.SummaryLastRow).PasteSpecial Paste:=xlPasteFormulas
End with
FYI: The ColToCopyFrom is not a merged cell. The ColToCopyTo is a merged cell. In this case, ColToCopyTo = "Q".
The code does paste the formulas and values in the proper cells, and I don't ever receive an error when the code runs, so I don't think there is anything wrong with the code. But after it runs is when the "#REF!" error shows up, so I'm guessing it has something to do with it.
The weird thing is, sometimes the above code works fine and doesn't cause the "#REF!" error. But under other conditions, it does. And sometimes, instead of saying "#REF!" it says "#VALUE!"
By the way, I know it's better not to have any merged cells, but I can't remove them because it would mess up the rest of the sheet. So I'm stuck with them.
Any thoughts on what is causing this error?