Fixing vba code that replaces empty columns with dates.

Copper Contributor

I'm working on some VB projects that has to do with generation of new excel sheets and some data analysis. In the final sheet generated, there are some columns that contain excel default dates (00.01.1900)

I later figured out there is a section of the code that converts blank cells from a previous sheet into the default dates in the final sheet. Here is some portion of the code I figured is the problem

vb.PNGSo what can I can change (I'm guessing its from the last 5 lines) from this code that would leave the empty cells in the prvs sheet to remain the same in the final sheet.

2 Replies
The problem is with the line where you add two cells together. If those cells are empty, the addition (+ sign) forces Excel to use the default numerical value of an empty cell, which is zero. SO the result of adding two empty cells is always a zero.
@Jan Thanks! I was finally able to fix it by removing the CDate function from the ws.Cells and equated the variable to itself!