Last active
March 10, 2019 12:18
-
-
Save ezhov-da/e1114ac74fa17760d719989b28b95813 to your computer and use it in GitHub Desktop.
vba transform condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre> | |
Sub execute() | |
Dim sourceNameSheet As String: sourceNameSheet = "свод" | |
Dim parseNameSheet As String: parseNameSheet = "parse" | |
Dim sourceWs As Worksheet | |
Set sourceWs = ActiveWorkbook.Worksheets(sourceNameSheet) | |
Dim targetWs As Worksheet | |
Set targetWs = ActiveWorkbook.Worksheets(parseNameSheet) | |
Dim startRow As Long: startRow = 2 | |
Dim rowConuntTargetSheet As Long: rowConuntTargetSheet = 2 | |
Do While (sourceWs.Cells(startRow, 1) <> "") | |
Dim nameTY As String | |
Dim monthData As String | |
Dim nameGm As String: nameGm = sourceWs.Cells(startRow, 3) | |
For c = 5 To 47 | |
nameTY = sourceWs.Cells(1, c) | |
monthData = sourceWs.Cells(startRow, c) | |
'Сделано 2 раза, так как в одной ячейке может быть две даты | |
rowConuntTargetSheet = checkAndCopyToSheet(targetWs, "11.2017", "11.17", monthData, "Ноябрь", nameTY, nameGm, rowConuntTargetSheet) | |
rowConuntTargetSheet = checkAndCopyToSheet(targetWs, "12.2017", "12.17", monthData, "Декабрь", nameTY, nameGm, rowConuntTargetSheet) | |
Next c | |
startRow = startRow + 1 | |
Debug.Print "process row: " & CStr(startRow) | |
Loop | |
Debug.Print "process complete" | |
End Sub | |
Private Function checkAndCopyToSheet(targetWs, checkValue, checkValue1, monthData, nameMonth, nameTY, nameGm, rowConuntTargetSheet) As Long | |
If InStr(monthData, checkValue) > 0 Or InStr(monthData, checkValue1) > 0 Then | |
targetWs.Cells(rowConuntTargetSheet, 1) = nameTY | |
targetWs.Cells(rowConuntTargetSheet, 2) = nameMonth | |
targetWs.Cells(rowConuntTargetSheet, 3) = nameGm | |
targetWs.Cells(rowConuntTargetSheet, 4) = monthData | |
rowConuntTargetSheet = rowConuntTargetSheet + 1 | |
End If | |
checkAndCopyToSheet = rowConuntTargetSheet | |
End Function | |
</pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment