Option Base 1
Sub A_Fixa_Användare_ID_Anstnr_TIP()
Application.ScreenUpdating = False
Dim år As Integer, månad As Integer
Dim anstnr As Long, kst As Long
Sheets("TIP Data").Select
Cells.Clear
Dim sokvag As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Importera"
.Title = "Välj TIP-fil att importera"
ingknapp = .Show
End With
If ingknapp = -1 Then
sokvag = Application.FileDialog( _
msoFileDialogFilePicker).SelectedItems(1)
Else
Exit Sub
End If
Workbooks.OpenText Filename:= _
sokvag, Origin:=xlMSDOS, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False
Selection.Copy
ActiveWindow.ActivateNext
Sheets("TIP Data").Select
Range("A1").Select
ActiveSheet.Paste
ActiveWindow.ActivateNext
Application.EnableEvents = False
Application.CutCopyMode = False
ActiveWindow.Close (False)
Application.EnableEvents = True
Sheets("TIP Data").Select
If Range("b1") = "Screener performance comparision - global" Then år = Left(Range("b3"), 4): månad = Mid(Range("b3"), 6, 2)
If Range("a1") = "Screener Performance Comparison" Then år = Left(Range("b3"), 4): månad = Mid(Range("b3"), 6, 2)
On Error Resume Next
Sheets("Tip Data").Select
If Range("b1") = "Screener performance comparision - global" Then
år = Left(Range("b3"), 4)
månad = Mid(Range("b3"), 6, 2)
Range("A5").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A5").Select
Do Until ActiveCell = ""
Application.StatusBar = ActiveCell.Row
Namn = ActiveCell
anstnr = ActiveCell.Offset(0, 1)
Do Until Not ActiveCell.Offset(0, 1) = anstnr Or ActiveCell = ""
Shift = ActiveCell.Offset(0, 2) + Shift
tid = ActiveCell.Offset(0, 3) + tid
Väskor = ActiveCell.Offset(0, 9) + Väskor
tip = ActiveCell.Offset(0, 10) + tip
Hit = ActiveCell.Offset(0, 11) + Hit
fal = ActiveCell.Offset(0, 12) + fal
RT = ActiveCell.Offset(0, 17) + RT
FT = ActiveCell.Offset(0, 18) + FT
räknare = räknare + 1
ActiveCell.Offset(1, 0).Select
If ActiveCell = "Totals" Then ActiveCell.Offset(1, 0).Select
If ActiveCell = "Averages" Then ActiveCell.Offset(1, 0).Select
Loop
Sheets("Sammanställning").Select
Range("a2").Select
Do Until ActiveCell = ""
If ActiveCell = anstnr Then
If ActiveCell.Offset(0, 1) = år Then
If ActiveCell.Offset(0, 2) = månad Then Exit Do
End If
End If
ActiveCell.Offset(1, 0).Select
Loop
Application.Wait Now + TimeSerial(0, 0, 1) '''Here is the first wait I inserted and this loop works fine with it
If ActiveCell.Offset(0, 0) = "" Then ActiveCell = anstnr
If ActiveCell.Offset(0, 1) = "" Then ActiveCell.Offset(0, 1) = år
If ActiveCell.Offset(0, 2) = "" Then ActiveCell.Offset(0, 2) = månad
If ActiveCell.Offset(0, 4) = "" Then ActiveCell.Offset(0, 4) = Namn
If ActiveCell.Offset(0, 5) = "" Then
ActiveCell.Offset(0, 5) = ActiveCell.Offset(0, 4)
ActiveCell.Offset(0, 4) = ""
Do Until Left(ActiveCell.Offset(0, 5), 1) = " "
ActiveCell.Offset(0, 4) = ActiveCell.Offset(0, 4) & Left(ActiveCell.Offset(0, 5), 1)
ActiveCell.Offset(0, 5) = Right(ActiveCell.Offset(0, 5), Len(ActiveCell.Offset(0, 5)) - 1)
Loop
ActiveCell.Offset(0, 5) = Right(ActiveCell.Offset(0, 5), Len(ActiveCell.Offset(0, 5)) - 1)
End If
ActiveCell.Offset(0, 11) = 0.01
ActiveCell.Offset(0, 14) = ((1 * tip) / tip) - (Hit / tip)
ActiveCell.Offset(0, 15) = RT / räknare
ActiveCell.Offset(0, 15).NumberFormat = "0.00"
ActiveCell.Offset(0, 16) = FT / räknare
ActiveCell.Offset(0, 16).NumberFormat = "0.00"
ActiveCell.Offset(0, 17) = Shift
ActiveCell.Offset(0, 18) = tip
ActiveCell.Offset(0, 19) = Väskor
ActiveCell.Offset(0, 21) = tid
If Not Hit = 0 Then
ActiveCell.Offset(0, 12) = Hit / tip
Else
ActiveCell.Offset(0, 12) = 0
End If
If Not fal = 0 Then
ActiveCell.Offset(0, 13) = fal / Väskor
Else
ActiveCell.Offset(0, 13) = 0
End If
If ActiveCell.Offset(0, 12) = 0# Then
If Not ActiveCell.Offset(0, 13) = 0# Then
x = 0.01
y = ActiveCell.Offset(0, 13)
Else
GoTo nästa
End If
Else
x = ActiveCell.Offset(0, 12)
y = ActiveCell.Offset(0, 13)
End If
If x = 1 Then x = 0.99
If y = 1 Then y = 0.99
If y <= 0.01 Then y = 0.01
With Application.WorksheetFunction
Result = .NormInv(x, 0, 1) - .NormInv(y, 0, 1)
End With
ActiveCell.Offset(0, 10) = Result
ActiveCell.Offset(0, 12) = ActiveCell.Offset(0, 12) * 100
ActiveCell.Offset(0, 13) = ActiveCell.Offset(0, 13) * 100
ActiveCell.Offset(0, 14) = ActiveCell.Offset(0, 14) * 100
nästa:
Shift = 0
tid = 0
Väskor = 0
tip = 0
Hit = 0
fal = 0
RT = 0
FT = 0
räknare = 0
Sheets("Tip Data").Select
Loop
End If
'****************************************** TIP Datavis rapport
If Range("a1") = "Screener Performance Comparison" Then
Sheets("TIP Data").Select
år = Left(Range("B6"), 4)
månad = Mid(Range("b6"), 6, 2)
Range("b9").Select
Do Until Not ActiveCell.Offset(0, -1) = "Mean"
Application.StatusBar = ActiveCell.Row
anstnr = ActiveCell.Offset(0, 0)
Namn = ActiveCell.Offset(0, 1)
d = ActiveCell.Offset(0, 2)
a = ActiveCell.Offset(0, 3)
Hit = ActiveCell.Offset(0, 4)
FA = ActiveCell.Offset(0, 5)
Miss = ActiveCell.Offset(0, 6)
RT_Hit = ActiveCell.Offset(0, 7)
RT_FA = ActiveCell.Offset(0, 8)
Work = ActiveCell.Offset(0, 9)
tip = ActiveCell.Offset(0, 10)
Bags = ActiveCell.Offset(0, 11)
ActiveCell.Offset(1, 0).Select
Sheets("Sammanställning").Select
Range("a2").Select
Do Until ActiveCell = ""
Application.Wait Now + TimeSerial(0, 0, 1)
If ActiveCell = anstnr Then
If ActiveCell.Offset(0, 1) = år Then
If ActiveCell.Offset(0, 2) = månad Then Exit Do
End If
End If
ActiveCell.Offset(1, 0).Select
Loop
If ActiveCell.Offset(0, 0) = "" Then ActiveCell = anstnr
If ActiveCell.Offset(0, 1) = "" Then ActiveCell.Offset(0, 1) = år
If ActiveCell.Offset(0, 2) = "" Then ActiveCell.Offset(0, 2) = månad
If ActiveCell.Offset(0, 4) = "" Then ActiveCell.Offset(0, 4) = Namn
ActiveCell.Offset(0, 10) = d
ActiveCell.Offset(0, 11) = a
ActiveCell.Offset(0, 12) = Hit
ActiveCell.Offset(0, 13) = FA
ActiveCell.Offset(0, 14) = Miss
ActiveCell.Offset(0, 15) = RT_Hit
ActiveCell.Offset(0, 16) = RT_FA
ActiveCell.Offset(0, 17) = Work
ActiveCell.Offset(0, 18) = tip
ActiveCell.Offset(0, 19) = Bags
Sheets("TIP Data").Select
Loop
End If
Tutor_Nivå = 2
tid = 1
D1 = 3
D2 = 2.75
Tippar = 20
Sheets("Sammanställning").Select
Range("g2").Select
Do Until ActiveCell.Offset(0, -ActiveCell.Column + 1) = ""
Application.Wait Now + TimeSerial(0, 0, 1)
If ActiveCell.Offset(0, 0) = "" Then ActiveCell.Offset(0, 0) = 0
If ActiveCell.Offset(0, 1) < tid Then ActiveCell.Offset(0, 1).Interior.ColorIndex = 3
If ActiveCell.Offset(0, 1) = "" Then ActiveCell.Offset(0, 1) = 0
If ActiveCell.Offset(0, 2) = "" Then ActiveCell.Offset(0, 2) = 0
If ActiveCell.Offset(0, 3) = "" Then ActiveCell.Offset(0, 3) = 0
If ActiveCell.Offset(0, 4) = "" Then ActiveCell.Offset(0, 4) = 0
If ActiveCell.Offset(0, 5) = "" Then ActiveCell.Offset(0, 5) = 0
If ActiveCell.Offset(0, 6) = "" Then ActiveCell.Offset(0, 6) = 0
If ActiveCell.Offset(0, 7) = "" Then ActiveCell.Offset(0, 7) = 0
If ActiveCell.Offset(0, 8) = "" Then ActiveCell.Offset(0, 8) = 0
If ActiveCell.Offset(0, 9) = "" Then ActiveCell.Offset(0, 9) = 0
If ActiveCell.Offset(0, 10) = "" Then ActiveCell.Offset(0, 10) = 0
If ActiveCell.Offset(0, 11) = "" Then ActiveCell.Offset(0, 11) = 0
If ActiveCell.Offset(0, 12) = "" Then ActiveCell.Offset(0, 12) = 0
If ActiveCell.Offset(0, 12) < Tippar Then ActiveCell.Offset(0, 12).Interior.ColorIndex = 45
If ActiveCell.Offset(0, 13) = "" Then ActiveCell.Offset(0, 13) = 0
ActiveCell.Offset(1, 0).Select
Loop
Sheets("KST från HR+").Select
Range("a2").Select
Do Until ActiveCell = ""
Application.Wait Now + TimeSerial(0, 0, 1)
Application.StatusBar = ActiveCell.Row & " " & ActiveCell.Text
anstnr = ActiveCell
kst = ActiveCell.Offset(0, 5)
ActiveCell.Offset(1, 0).Select
Sheets("Sammanställning").Select
Range("a2").Select
Do Until ActiveCell = ""
If ActiveCell = anstnr Then
If ActiveCell.Offset(0, 20) = "" Then ActiveCell.Offset(0, 20) = kst
End If
ActiveCell.Offset(1, 0).Select
Loop
Sheets("KST från HR+").Select
Loop
Sheets("Sammanställning").Select
Columns("H:H").Select
Selection.Replace What:=".", Replacement:=",", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("F2").Select
Do Until ActiveCell.Offset(0, -5) = ""
Application.Wait Now + TimeSerial(0, 0, 1)
If ActiveCell = "" Then
Do Until Right(ActiveCell.Offset(0, -1), 1) = " "
ActiveCell = Right(ActiveCell.Offset(0, -1), 1) & ActiveCell
ActiveCell.Offset(0, -1) = Left(ActiveCell.Offset(0, -1), Len(ActiveCell.Offset(0, -1)) - 1)
Loop
ActiveCell.Offset(0, -1) = Left(ActiveCell.Offset(0, -1), Len(ActiveCell.Offset(0, -1)) - 1)
End If
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
Sheets("TIP Data").Select
Cells.Clear
Sheets("Sammanställning").Select
End sub