Poeli
05-15-2010, 07:12 AM
Hi all, I'm new here and I really suck at VBA... I study airplane engineering but we also have vba excel, we made an excercise in class, but I really don't get it... This is the code:
Option Explicit
Function berekenTijd _
(aankomsthuidig As Date, landingvorig As Date) As Date
Dim landinghuidig As Date
landinghuidig = landingvorig + TimeValue("0:10:0")
If aankomsthuidig > landinghuidig Then
landinghuidig = aankomsthuidig
End If
berekenTijd = landinghuidig
End Function
Sub brengDataSamenEnSorteer()
Dim aantalbaan1 As Integer
Dim aantalbaan2 As Integer
Sheets("eindresultaat").Select
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Sheets("Landingsbaan1").Select
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
aantalbaan1 = Selection.Rows.Count
Sheets("Eindresultaat").Select
Range("A2").Select
ActiveSheet.Paste
Sheets("Landingsbaan2").Select
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
aantalbaan2 = Selection.Rows.Count
Sheets("Eindresultaat").Select
Range("A" & (aantalbaan1 + 2)).Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Eindresultaat").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Eindresultaat").Sort.SortFields.Add Key:=Range( _
"D1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Eindresultaat").Sort
.SetRange Range("A2:F" & (aantalbaan1 + aantalbaan2 + 1))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
I know why we use the range and select certain cells, but i don't know why you go for example xtoright.select, can't you say for example range (cellyouwanttoselect).slect instead of range(selection,selection.end(x1toright)).select?
What I also don't understand is the complete last paragraph.. Certainly the .setrange, .header and ect not.
Pff I completely suck at it and this is the kind of excercise we get on our exam... I do know what most of the things mean, but i don't see it as a whole..Does anyone has some tips for me? We don't even have a decent book about it, only excercises...
Thank you
Option Explicit
Function berekenTijd _
(aankomsthuidig As Date, landingvorig As Date) As Date
Dim landinghuidig As Date
landinghuidig = landingvorig + TimeValue("0:10:0")
If aankomsthuidig > landinghuidig Then
landinghuidig = aankomsthuidig
End If
berekenTijd = landinghuidig
End Function
Sub brengDataSamenEnSorteer()
Dim aantalbaan1 As Integer
Dim aantalbaan2 As Integer
Sheets("eindresultaat").Select
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Sheets("Landingsbaan1").Select
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
aantalbaan1 = Selection.Rows.Count
Sheets("Eindresultaat").Select
Range("A2").Select
ActiveSheet.Paste
Sheets("Landingsbaan2").Select
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
aantalbaan2 = Selection.Rows.Count
Sheets("Eindresultaat").Select
Range("A" & (aantalbaan1 + 2)).Select
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Eindresultaat").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Eindresultaat").Sort.SortFields.Add Key:=Range( _
"D1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Eindresultaat").Sort
.SetRange Range("A2:F" & (aantalbaan1 + aantalbaan2 + 1))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
I know why we use the range and select certain cells, but i don't know why you go for example xtoright.select, can't you say for example range (cellyouwanttoselect).slect instead of range(selection,selection.end(x1toright)).select?
What I also don't understand is the complete last paragraph.. Certainly the .setrange, .header and ect not.
Pff I completely suck at it and this is the kind of excercise we get on our exam... I do know what most of the things mean, but i don't see it as a whole..Does anyone has some tips for me? We don't even have a decent book about it, only excercises...
Thank you