PDA

View Full Version : Help with consolidating date on a worksheet from other worksheets



Shareefm
12-03-2015, 06:11 AM
Hi,

VBA noob here. I have been learning VBA for about a week now and I'm trying to work on a project and here's the problem I'm having.

My workbook has about 10 to 12 different worksheets on it and I'm supposed to consolidate all of them into one single sheet. Each sheet has a column of dates in column "A" and column "B" is of values of type double.

My consolidated sheet should have column "A" with all the dates from 01/01/2004, column "B" with the values from sheet1 and column "C" with the values from sheet2 and so forth.

If there is a date without values then The corresponding cell is supposed to be left as blank.

The Dates starts from 01/01/2004 and go on to the present day. I'm having a problem with sheet8 which doesn't start on that the starting date. Rather it starts much later. When I try to use the code that I have made, it starts at the correct date but the value is wrong.

What a my doing wrong here? How can I fix this? I am just a noob



Sub move_through_pages7()

For i = 3 To 1000
a = 0

If ActiveWorkbook.Worksheets("Consolidated").Cells(i, "A").Value = ActiveWorkbook.Worksheets("Sheet8").Cells(3, "A").Value Then

For m = i To 3000
If ActiveWorkbook.Worksheets("Consolidated").Cells(m + a, "A").Value = ActiveWorkbook.Worksheets("Sheet8").Cells(m, "A").Value Then
Cells(m + a, 1).Offset(0, 8) = ActiveWorkbook.Worksheets("Sheet8").Cells(m + a, "B")
Else:
a = a + 1
Cells(m + a, 1).Offset(0, 8) = ActiveWorkbook.Worksheets("Sheet8").Cells(m, "B")

End If

Next m


End If

Next i
End Sub


This is a second subfunction in my main function. The other subfunction populates the Consolidated worksheet with dates.