Hi,
I've never used Macros before and am currently trying to write one to do something that is very straight forward.
I have a column with the date in it.
I then have a row heading with times in it (half hourly increment)
Under the half hourly increments I have data corresponding to each day.
e.g.
00:00 00:30 01:00 ....
01-Jan-01 20 27 22 ....
02-Jan-01 15 12 31 ....
I want to move the data that is currently running in rows to run in columns.
This way I will have
Date & Time in one column and the next column will have the data
e.g.
01-Jan-01 00:00 20
01-Jan-01 00:30 27
01-Jan-01 01:00 22 etc..
The problem is I have data for the past 5 years and so want to do it with a macro rather than by hand!!!
Also I thought it may help me to learn a bit about macros and visual basic?! I can find no examples of anyone trying to do anything like this so have pieced together the following code... I know it's wrong and I think I know where it's wrong but I don't know how to fix it or where to look to fix it!
The code so far:
Sub Halfhourly()
Application.EnableEvents = False
Application.ScreenUpdating = False
Range("E:E").Select
Selection.NumberFormat = "m/d/yyyy h:mm"
Dim l As Integer
Dim m As Integer
Dim n As Integer
For l = 3 To 9403 Step 47
For m = 2 To 9402 Step 47
For n = 47 To 9447 Step 47
Rows(l, l).Select
Selection.Insert Shift:=x47Down
Range(m, 5).Copy
Range(l, 5).Select
ActiveCell.FormulaR1C1 = Paste + TimeValue("0:30")
Range(Cells(m, 5), Cells(l, 5)).Select
Selection.AutoFill Destination:=Range("Em:En"), Type:=xlFillDefault
Next n
Next m
Next l
Range(m, 8).Select
Dim i As Integer
Dim j As Integer
Dim k As Integer
For i = 1 To 46
For j = -1 To -46
For k = 2 To 47
ActiveCell.Selection.Copy
ActiveCell.Offset(i, j).Paste
ActiveCell.Offset(j, k).Select
Next k
Next j
Next i
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
I've never used Macros before and am currently trying to write one to do something that is very straight forward.
I have a column with the date in it.
I then have a row heading with times in it (half hourly increment)
Under the half hourly increments I have data corresponding to each day.
e.g.
00:00 00:30 01:00 ....
01-Jan-01 20 27 22 ....
02-Jan-01 15 12 31 ....
I want to move the data that is currently running in rows to run in columns.
This way I will have
Date & Time in one column and the next column will have the data
e.g.
01-Jan-01 00:00 20
01-Jan-01 00:30 27
01-Jan-01 01:00 22 etc..
The problem is I have data for the past 5 years and so want to do it with a macro rather than by hand!!!
Also I thought it may help me to learn a bit about macros and visual basic?! I can find no examples of anyone trying to do anything like this so have pieced together the following code... I know it's wrong and I think I know where it's wrong but I don't know how to fix it or where to look to fix it!
The code so far:
Sub Halfhourly()
Application.EnableEvents = False
Application.ScreenUpdating = False
Range("E:E").Select
Selection.NumberFormat = "m/d/yyyy h:mm"
Dim l As Integer
Dim m As Integer
Dim n As Integer
For l = 3 To 9403 Step 47
For m = 2 To 9402 Step 47
For n = 47 To 9447 Step 47
Rows(l, l).Select
Selection.Insert Shift:=x47Down
Range(m, 5).Copy
Range(l, 5).Select
ActiveCell.FormulaR1C1 = Paste + TimeValue("0:30")
Range(Cells(m, 5), Cells(l, 5)).Select
Selection.AutoFill Destination:=Range("Em:En"), Type:=xlFillDefault
Next n
Next m
Next l
Range(m, 8).Select
Dim i As Integer
Dim j As Integer
Dim k As Integer
For i = 1 To 46
For j = -1 To -46
For k = 2 To 47
ActiveCell.Selection.Copy
ActiveCell.Offset(i, j).Paste
ActiveCell.Offset(j, k).Select
Next k
Next j
Next i
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub