You are on page 1of 11

MACRO – Fill-in Blanks

Sub Macro1()

Dim x, curcol, nrrows As Integer

Dim curtext As String

nrrows = CInt(InputBox("Introduceti numarul de randuri"))

curcol = ActiveCell.Column

startrow = ActiveCell.Row

curtext = ActiveCell.Value

For x = startrow To nrrows

If IsEmpty(ActiveSheet.Cells(x, curcol).Value) Then

ActiveSheet.Cells(x, curcol).Value = curtext

Else

curtext = ActiveSheet.Cells(x, curcol)

End If

Next x

End Sub
/************* Inlocuire judete *************/

Sub test()

Dim lung, scurt

Dim nrreg, x As Integer

Dim check

Dim curarr, curarr2 As Variant

lung = Array("ALBA", "ARAD", "ARGES", "BACAU", "BIHOR", "BISTRITA", "BOTOSANI", "BRAILA",


"BRASOV", "BUCURESTI", "BUZAU", "CALARASI", "CARAS SEVERIN", "CLUJ", "CONSTANTA", "COVASNA",
"DAMBOVITA", "DOLJ", "GALATI", "GIURGIU", "GORJ", "HARGHITA", "HUNEDOARA", "IALOMITA", "IASI",
"MARAMURES", "MEHEDINTI", "MURES", "NEAMT", "OLT", "PRAHOVA", "SALAJ", "SATU MARE",
"SIBIU", "SUCEAVA", "TELEORMAN", "TIMIS", "TULCEA", "VALCEA", "VASLUI", "VRANCEA")

scurt = Array("AB", "AR", "AG", "BC", "BH", "BN", "BT", "BR", "BV", "B", "BZ", "CL", "CS", "CJ", "CT", "CV",
"DB", "DJ", "GL", "GR", "GJ", "HR", "HD", "IL", "IS", "MM", "MH", "MS", "NT", "OT", "PH", "SJ", "SM",
"SB", "SV", "TR", "TM", "TL", "VL", "VS", "VN")

curarr = lung
curarr2 = scurt

If Len(Selection.Cells(1, 1).Value) < 3 Then

sens = 1

curarr = scurt

curarr2 = lung

End If

For Each celreg In Selection.Cells

check = False

x=0

Do

If curarr(x) = celreg.Value Then

celreg.Value = curarr2(x)

check = True

End If

x=x+1

Loop Until (check = True) Or (x = 41)

Next

End Sub

Sub ytd()

'

' ytd Macro

' Macro recorded 5/9/2006 by MihaelaM


'

'

Columns("M:M").Select

Selection.Cut

Columns("G:G").Select

Selection.Insert Shift:=xlToRight

Columns("H:H").Select

Selection.Insert Shift:=xlToRight

Selection.NumberFormat = "General"

Range("H2").Select

ActiveCell.FormulaR1C1 = _

"=IF(RC[1]=""E1"",""ROAD"",IF(RC[1]=""E2"",""RAIL"",IF(RC[1]=""E3"",""BOAT"","""")))"

Range("H2").Select

Selection.AutoFill Destination:=Range("H2:H65536")

Range("H2:H65536").Select

Range("I1").Select

Selection.Cut Destination:=Range("H1")

Columns("H:H").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("I:I").Select

Application.CutCopyMode = False

Selection.Delete Shift:=xlToLeft

Columns("I:I").Select

Selection.Insert Shift:=xlToRight

Range("I2").Select

ActiveCell.FormulaR1C1 = _
"=IF(RC[1]=""D"",""DELIVERED"",IF(OR(RC[1]=""F"",UPPER(RC[1])=""EXW""),""Exworks"",IF(RC[1]="""","
""",RC[1])))"

Range("I2").Select

Selection.AutoFill Destination:=Range("I2:I65536")

Range("I2:I65536").Select

Range("J1").Select

Selection.Cut Destination:=Range("I1")

Columns("I:I").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("J:J").Select

Application.CutCopyMode = False

Selection.Delete Shift:=xlToLeft

Range("O2").Select

Columns("J:J").Select

Selection.Insert Shift:=xlToRight

Range("J2").Select

ActiveCell.FormulaR1C1 = _

"=IF(RC[1]=""Klinker"",""Klinker"",IF(RC[1]=""Filler"",""FILLER"",IF(OR(RC[1]=""Doroport"",RC[1]=""Doro
sol""),""ROAD BINDE"",IF(OR(RC[1]=""II 42,5"",RC[1]=""I 52,5""),""WHITE"",IF(AND(RC[1]="""",RC[-
3]<>0),""GREY"",IF(AND(RC[1]="""",RC[-3]=""""),"""",""GREY""))))))"

Range("J2").Select

Selection.AutoFill Destination:=Range("J2:J65536")

Range("J2:J65536").Select

Range("K1").Select

Selection.Cut Destination:=Range("J1")

Columns("J:J").Select
Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("L:L").Select

Selection.Insert Shift:=xlToRight

Selection.NumberFormat = "General"

Range("L2").Select

ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""",RC[1],RC[-1])"

Range("L2").Select

Selection.AutoFill Destination:=Range("L2:L65536")

Range("L2:L65536").Select

Columns("L:L").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("K:K").Select

Application.CutCopyMode = False

Selection.Delete Shift:=xlToLeft

Columns("M:M").Select

Application.CutCopyMode = False

Selection.Cut

Columns("L:L").Select

Selection.Insert Shift:=xlToRight

Columns("M:M").Select

Selection.Insert Shift:=xlToRight

Selection.NumberFormat = "General"

Range("M2").Select

ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]=""BULK"",""BULK"",IF(UPPER(RIGHT(RC[1],9))=""PALETIZAT"",""palletized"",IF(AND(RC[-
1]=""BAGS"",UPPER(RIGHT(RC[1],9))<>""PALETIZAT""),""BAGS"","""")))"

Range("M2").Select

Selection.AutoFill Destination:=Range("M2:M65536")

Range("M2:M65536").Select

Range("M5").Select

ActiveWindow.SmallScroll Down:=-15

Columns("M:M").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("N:N").Select

Application.CutCopyMode = False

Selection.Delete Shift:=xlToLeft

Columns("N:N").Select

Selection.Insert Shift:=xlToRight

Range("N2").Select

ActiveCell.FormulaR1C1 = _

"=IF(RC[1]=""R104"",""Campulung"",IF(RC[1]=""R102"",""Alesd"",IF(RC[1]=""R103"",""Turda"",IF(RC[1]=
""R105"",""Terminal Progresu"",IF(RC[1]=""R107"",""Blending Plant
Pr"",IF(RC[1]=""R106"",""Port"",""""))))))"

Range("N2").Select

Selection.AutoFill Destination:=Range("N2:N65536")

Range("N2:N65536").Select

Range("O1").Select

Selection.Cut Destination:=Range("N1")

Columns("N:N").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _


:=False, Transpose:=False

Columns("O:O").Select

Application.CutCopyMode = False

Selection.Delete Shift:=xlToLeft

Range("P2").Select

ActiveCell.FormulaR1C1 = "=IF(RC[-1]<>"""",MONTH(RC[-1]),"""")"

Range("P2").Select

Selection.AutoFill Destination:=Range("P2:P65536")

Range("P2:P65536").Select

Columns("P:P").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("Q2").Select

Application.CutCopyMode = False

ActiveCell.FormulaR1C1 = _

"=IF(RC[-1]=1,""January"",IF(RC[-1]=2,""February"",IF(RC[-1]=3,""March"",IF(RC[-
1]=4,""April"",IF(RC[-1]=5,""May"",IF(RC[-1]=6,""June"",""""))))))"

Range("Q2").Select

Selection.AutoFill Destination:=Range("Q2:Q65536")

Range("Q2:Q65536").Select

Range("R2").Select

ActiveCell.FormulaR1C1 = _

"=IF(RC[-2]=7,""July"",IF(RC[-2]=8,""August"",IF(RC[-2]=9,""September"",IF(RC[-
2]=10,""October"",IF(RC[-2]=11,""November"",IF(RC[-2]=12,""December"",""""))))))"

Range("R2").Select

Selection.AutoFill Destination:=Range("R2:R65536")

Range("R2:R65536").Select

Range("S2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-2]="""",RC[-1],RC[-2])"

Range("S2").Select

Selection.AutoFill Destination:=Range("S2:S65536")

Range("S2:S65536").Select

Columns("S:S").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("P:R").Select

Range("R1").Activate

Application.CutCopyMode = False

Selection.Delete Shift:=xlToLeft

Range("Q2").Select

ActiveCell.FormulaR1C1 = "=IF(RC[-2]<>"""",YEAR(RC[-2]),"""")"

Range("Q2").Select

Selection.AutoFill Destination:=Range("Q2:Q65536")

Range("Q2:Q65536").Select

Columns("Q:Q").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("R2").Select

Application.CutCopyMode = False

ActiveCell.FormulaR1C1 = _

"=IF(OR(RC[-8]=""White"",RC[-8]=""GREY""),""CEMENT"",RC[-8])"

Range("R2").Select

Selection.AutoFill Destination:=Range("R2:R65536")

Range("R2:R65536").Select

Range("S2").Select
ActiveCell.FormulaR1C1 = "=RC[-2]"

Range("S2").Select

Selection.AutoFill Destination:=Range("S2:S65536")

Range("S2:S65536").Select

Columns("R:S").Select

Range("S1").Activate

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("R4").Select

Range("E2").Select

Columns("E:E").Select

Selection.Insert Shift:=xlToRight

Selection.NumberFormat = "General"

Range("E2").Select

ActiveCell.FormulaR1C1 = _

"=IF(AND(RC[-1]="""",RC[-2]<>""""),""XE"",IF(RC[-1]<>"""",RC[-1],""""))"

Range("E2").Select

Selection.AutoFill Destination:=Range("E2:E65536")

Range("E2:E65536").Select

Range("D1").Select

Selection.Cut Destination:=Range("E1")

Columns("E:E").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("D:D").Select

Application.CutCopyMode = False

Selection.Delete Shift:=xlToLeft
Columns("G:G").Select

Selection.Insert Shift:=xlToRight

Selection.NumberFormat = "General"

Range("G2").Select

ActiveCell.FormulaR1C1 = _

"=IF(AND(RC[-1]="""",RC[-2]<>""""),""XE"",IF(RC[-1]<>"""",RC[-1],""""))"

Range("G2").Select

Selection.AutoFill Destination:=Range("G2:G65536")

Range("G2:G65536").Select

Range("F1").Select

Selection.Cut Destination:=Range("G1")

Columns("G:G").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("F:F").Select

Application.CutCopyMode = False

Selection.Delete Shift:=xlToLeft

End Sub