Not sure what code to use.

Jacko1996

New Member
Joined
May 29, 2015
Messages
21
Hey so I have a whole bunch of daily data for a weather station. What I want it to do is create a table made of monthly data for all the years using the daily data. I'm not sure what formula to use.

The table below shows kind what it looks like, however on a much larger scale

YearMonthDayRainfall amount (millimetres)
18931210
18931220
18931230
18931240
18931250
18931260
18931270
18931280
18931290
189312100
189312110
189312120
189312130
189312140
189312150
189312160
189312170
189312182
189312190
189312200
189312210
189312220
189312230
189312240
189312250
189312260
189312270
189312280
189312290
189312300
189312310
1894117.9
1894120
1894130
1894140
1894150
1894162.3
1894170
1894180
18941964.5
189411012.7
18941110
18941120
189411331.8
189411429.7
189411538.4
18941168.1
18941170
18941180
18941199.7
18941200
18941210
189412299.1
18941230
189412416.5
189412514.7
18941260.3
18941274.8
18941284.8
189412956.4

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>

Below is what i want it to look like the values are made up but those would be the values of rainfall for the months.

YearJanFebMarAprMayJuneJulyAugSepNovOctDec
1983000000462012080
19842304366826130034234679

<tbody>
</tbody>
 
Sorry I used Rick Rothestein code but perhaps you hiker95 could tell me what these values mean?

Thanks
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Sorry I used Rick Rothestein code but perhaps you hiker95 could tell me what these values mean?

Jacko1996,

You will have to ask Rick Rothstein to explain his macro code to you.
 
Upvote 0
Not important.. but here's 2 alternate ways of doing this: :)
Code:
.Range("A1:M1") = Array("Year", "Jan", "Feb", "Mar", "Apr", "May", _
                      "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

Code:
[A1:M1] = Split("Year" & vbLf & Join(Application.GetCustomListContents(3), vbLf), vbLf)

or

Code:
[A1] = "Year": [B1:M1] = Application.GetCustomListContents(3)
 
Upvote 0
Hey Rick Rothstein

How am I able to add a annual column to this code to create a sum of that years data?

So It looks like This

YearJanFebMarAprMayJunJulAugSepOctNovDecAnnual
19920817.9533.6268.5121.522.122.120.47113.6172.2130.62193.5
1993143.9228.6268507617.9105.510378.7103.6178.6170.91524.7

<colgroup><col span="8"><col><col><col span="3"><col></colgroup><tbody>
</tbody>

The Code I have used is
Sub YearMonthRainfallToo()
Dim r As Long, LastRow As Long, Data As Variant, Result As Variant
LastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Data = Sheets("Sheet1").Range("A2:D" & LastRow)
ReDim Result(Data(1, 1) To Data(UBound(Data), 1), 0 To 12)
For r = 1 To UBound(Data) - LBound(Data) + 1
If Result(Data(r, 1), 0) = "" Then Result(Data(r, 1), 0) = Data(r, 1)
Result(Data(r, 1), Data(r, 2)) = Result(Data(r, 1), Data(r, 2)) + Data(r, 4)
Next
With Sheets("Rainfall")
.Cells.Clear
.Range("A1:M1") = Array("Year", "Jan", "Feb", "Mar", "Apr", "May", _
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
.Range("A2").Resize(UBound(Result) - LBound(Result) + 1, 13) = Result
On Error Resume Next
.Range("A2").Resize(UBound(Result) - LBound(Result) + 1, 13).SpecialCells(xlBlanks) = 0
On Error GoTo 0
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,516
Messages
6,125,284
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top