Sie sind auf Seite 1von 6

Sub data_for_DB()

Dim wbDst As Workbook


Dim wbSrc As Workbook
Dim wsSrc As Worksheet
Dim MyPath As String
Dim strFilename As String

Dim lastrow As Long ' for fill range


newdate = Format(Date, "[$-409]d-mmm-yyyy;@")
' Macro recorded 6/10/2016 by Ali Abdalhussein
'del old data
On Error Resume Next
Kill "C:\3G congestion\data per cell.xlsx"
On Error GoTo 0
On Error Resume Next
Kill "C:\3G congestion\3G Daily main KPI.xlsx"
On Error GoTo 0
On Error Resume Next
Kill "C:\3G congestion\KPI.xlsx"
On Error GoTo 0
'open KPI sheet
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False

Workbooks.OpenText Filename:="C:\3G congestion\3G Daily main KPI.txt", _


Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7,
1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1),
Array(14, 1), Array(15 _
, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1),
Array(21, 1), _
Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1),
Array(27, 1), Array( _
28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array(33,
1), Array(34, 1), _
Array(35, 1), Array(36, 1), Array(37, 1), Array(38, 1)),
TrailingMinusNumbers:=True
Sheets("3G Daily main KPI").Select
Sheets("3G Daily main KPI").Name = "data"

' modify sheet


Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("A:A").EntireColumn.AutoFit
Range("B1").Select
ActiveCell.FormulaR1C1 = "Week No"
Columns("E:E").Select
Columns("D:D").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("C:C").EntireColumn.AutoFit
Columns("E:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D1").Select
ActiveCell.FormulaR1C1 = "BSC name"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Band"
Range("E2").Select

Worksheets("data").Cells(1, 42) = "Cells count RRC"


Worksheets("data").Cells(1, 43) = "Cells count CS"
Worksheets("data").Cells(1, 44) = "Cells count PS"
Worksheets("data").Cells(1, 45) = "Cells count RTWP"
Worksheets("data").Cells(1, 46) = "check all type code cong"
Worksheets("data").Cells(1, 47) = "RRC code cong Criteria"
Worksheets("data").Cells(1, 48) = "CS RAB code cong Criteria"
Worksheets("data").Cells(1, 49) = "PS RAB code cong Criteria"
' add cell report sheet & open wb
Worksheets.Add().Name = "Cell report"
ActiveSheet.Move after:=Sheets(ActiveWorkbook.Sheets.Count)
Application.ScreenUpdating = False
Filename = Dir("C:\3G congestion\*report*.xls", vbNormal)
Do Until Filename = ""
If Filename <> ThisWB Then
Set CR = Workbooks.Open("C:\3G congestion" & "\" & Filename,
IgnoreReadOnlyRecommended:=False, editable:=False, notify:=False, ReadOnly:=True)

End If
Filename = Dir()
Loop
Columns("B:K").Select
Selection.Delete Shift:=xlToLeft
Columns("C:C").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlToLeft
Columns("A:B").Select
ActiveSheet.Range("$A$1:$B$15000").RemoveDuplicates Columns:=Array(1, 2), _
Header:=xlYes
Columns("A:B").Select
Selection.Copy
Windows("3G Daily main KPI.txt").Activate
Sheets("Cell report").Select
ActiveSheet.Paste

CR.Close

' 1st modify


Windows("3G Daily main KPI.txt").Activate
Sheets("data").Select
Columns("G:G").Select
Selection.Copy
Columns("E:E").Select
ActiveSheet.Paste
Columns("G:G").Select
Selection.Replace What:="A1", Replacement:="1", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="B1", Replacement:="2", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="C1", Replacement:="3", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="D1", Replacement:="4", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="A2", Replacement:="4", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="B2", Replacement:="5", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="C2", Replacement:="6", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="D2", Replacement:="8", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="A3", Replacement:="7", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="B3", Replacement:="8", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="C3", Replacement:="9", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="A3", Replacement:="1", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="-", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="_", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("E1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Band"
Columns("E:E").Select
Selection.Replace What:="*-", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="A1", Replacement:="U900", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="b1", Replacement:="U900", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="b1", Replacement:="U900", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="C1", Replacement:="U900", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="D1", Replacement:="U900", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="A2", Replacement:="U2100_1st", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="b2", Replacement:="U2100_1st", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="c2", Replacement:="U2100_1st", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="d2", Replacement:="U2100_1st", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="a3", Replacement:="U2100_2nd", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="b3", Replacement:="U2100_2nd", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="c3", Replacement:="U2100_2nd", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="c3", Replacement:="U2100_2nd", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

' Vlookup BSC


Windows("3G Daily main KPI.txt").Activate
Sheets("data").Select

Worksheets("data").Activate
Columns("F:F").Select
Selection.Copy
Columns("H:H").Select
ActiveSheet.Paste
Range("H1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Site ID"
Columns("H:H").Select
Selection.Replace What:="*_", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="-*", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Dim SourceLastRow As Long


Dim OutputLastRow As Long
Dim sourceSheet As Worksheet
Dim outputSheet As Worksheet

'What are the names of our worksheets?


Set sourceSheet = Worksheets("Cell report")
Set outputSheet = Worksheets("data")

'Determine last row of source


With sourceSheet
SourceLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
With outputSheet
'Determine last row in col P
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
'Apply our formula
.Range("d2:d" & OutputLastRow).Formula = _
"=VLOOKUP(h2,'" & sourceSheet.Name & "'!$a$2:$b$" & SourceLastRow & ",2,0)"
End With

Columns("D:D").Select
Selection.Copy
Range("D1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Cell report").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.Delete
' fill range FUNCATION
'1. week number B col

Worksheets("data").Activate
Columns("F:F").Select
Selection.Replace What:="2935_B3", Replacement:="2935-B3", LookAt:=xlPart _
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

lastrow = Cells(Rows.Count, "G").End(xlUp).Row


Range("B2").Select
ActiveCell.FormulaR1C1 = "=WEEKNUM(RC[-1])"
Range("B2").Select
Selection.NumberFormat = "General"

Range("B2").AutoFill Destination:=Range("B2:B" & lastrow), Type:=xlFillDefault


'fill C column

Range("B2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
On Error Resume Next
Kill "C:\3G congestion\*report*.xls"
On Error GoTo 0
'2. fill range col from AP - AW
Worksheets("data").Activate
lastrow = Cells(Rows.Count, "G").End(xlUp).Row
Range("AP2").Select
ActiveCell.FormulaR1C1 = "=COUNTIFS(C[-35],RC[-35],C[-33],"">100"")"
Range("AP2").AutoFill Destination:=Range("AP2:AP" & lastrow), Type:=xlFillDefault
'fill C column
lastrow = Cells(Rows.Count, "G").End(xlUp).Row
Range("AQ2").Select
ActiveCell.FormulaR1C1 = "=COUNTIFS(C[-36],RC[-36],C[-33],"">100"")"
Range("AQ2").AutoFill Destination:=Range("AQ2:AQ" & lastrow), Type:=xlFillDefault
lastrow = Cells(Rows.Count, "G").End(xlUp).Row
Range("AR2").Select
ActiveCell.FormulaR1C1 = "=COUNTIFS(C[-37],RC[-37],C[-33],"">100"")"
Range("AR2").Select
Range("AR2").AutoFill Destination:=Range("AR2:AR" & lastrow), Type:=xlFillDefault
lastrow = Cells(Rows.Count, "G").End(xlUp).Row
Range("AS2").Select
ActiveCell.FormulaR1C1 = "=COUNTIFS(C[-38],RC[-38],C[-31],"">-90"")"
Range("AS2").AutoFill Destination:=Range("AS2:AS" & lastrow), Type:=xlFillDefault

Range("AU2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-5]=0,""Cell without cong"",IF(OR(RC[-5]=1,RC[-5]=2),""Wait next
week"",IF(OR(RC[-5]=3,RC[-5]=4),""Need Mointer"",""Need Fast Action"")))"

Range("AU2").AutoFill Destination:=Range("AU2:AU" & lastrow),


Type:=xlFillDefault

Range("AV2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-5]=0,""Cell without cong"",IF(OR(RC[-5]=1,RC[-5]=2),""Wait Next
days"",IF(OR(RC[-5]=3,RC[-5]=4),""Need Moniter"",""Need Fast Action"")))"

Range("AV2").AutoFill Destination:=Range("AV2:AV" & lastrow),


Type:=xlFillDefault

Range("AW2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-5]=0,""Cell without cong"",IF(OR(RC[-5]=1,RC[-5]=2),""Wait Next
days"",IF(OR(RC[-5]=3,RC[-5]=4),""Need Moniter"",""Need Fast Action"")))"
Range("AW2").AutoFill Destination:=Range("AW2:AW" & lastrow),
Type:=xlFillDefault

Cells.Select
Range("O1").Activate
Selection.Replace What:="#DIV/0", Replacement:="0", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("A2").Select
End Sub

Das könnte Ihnen auch gefallen