Shortining code

Delftsblauw

New Member
Joined
Jul 9, 2014
Messages
4
Hi,

I'm a new member, but in the last year i always checked for solutions in this forum. But now i'm stuck with shorting some code i made.

Is there a solution for shorting this code

Code:
Sub Januari1()
Dim Medewerker, Maand As String
Medewerker = Verlof.ComboBox1.Value
Maand = "Januari"
Dim result As String
result = Application.WorksheetFunction.VLookup(Medewerker, Sheets(Maand).Range("A:DV"), 126, False)
If Sheets("Temp").Range("C1") = 1 And Sheets("Temp").Range("B1") = 1 Then Sheets(Maand).Range("B" & result & ":E" & result) = "x"
If Sheets("Temp").Range("C2") = 1 And Sheets("Temp").Range("B2") = 2 Then Sheets(Maand).Range("F" & result & ":I" & result) = "x"
If Sheets("Temp").Range("C3") = 1 And Sheets("Temp").Range("B3") = 3 Then Sheets(Maand).Range("J" & result & ":M" & result) = "x"
If Sheets("Temp").Range("C4") = 1 And Sheets("Temp").Range("B4") = 4 Then Sheets(Maand).Range("N" & result & ":Q" & result) = "x"
If Sheets("Temp").Range("C5") = 1 And Sheets("Temp").Range("B5") = 5 Then Sheets(Maand).Range("R" & result & ":U" & result) = "x"
If Sheets("Temp").Range("C6") = 1 And Sheets("Temp").Range("B6") = 6 Then Sheets(Maand).Range("V" & result & ":Y" & result) = "x"
If Sheets("Temp").Range("C7") = 1 And Sheets("Temp").Range("B7") = 7 Then Sheets(Maand).Range("Z" & result & ":AC" & result) = "x"
If Sheets("Temp").Range("C8") = 1 And Sheets("Temp").Range("B8") = 8 Then Sheets(Maand).Range("AD" & result & ":AG" & result) = "x"
If Sheets("Temp").Range("C9") = 1 And Sheets("Temp").Range("B9") = 9 Then Sheets(Maand).Range("AH" & result & ":AK" & result) = "x"
If Sheets("Temp").Range("C10") = 1 And Sheets("Temp").Range("B10") = 10 Then Sheets(Maand).Range("AL" & result & ":AO" & result) = "x"
If Sheets("Temp").Range("C11") = 1 And Sheets("Temp").Range("B11") = 11 Then Sheets(Maand).Range("AP" & result & ":AS" & result) = "x"
If Sheets("Temp").Range("C12") = 1 And Sheets("Temp").Range("B12") = 12 Then Sheets(Maand).Range("AT" & result & ":AW" & result) = "x"
If Sheets("Temp").Range("C13") = 1 And Sheets("Temp").Range("B13") = 13 Then Sheets(Maand).Range("AX" & result & ":BA" & result) = "x"
If Sheets("Temp").Range("C14") = 1 And Sheets("Temp").Range("B14") = 14 Then Sheets(Maand).Range("BB" & result & ":BE" & result) = "x"
If Sheets("Temp").Range("C15") = 1 And Sheets("Temp").Range("B15") = 15 Then Sheets(Maand).Range("BF" & result & ":BI" & result) = "x"
If Sheets("Temp").Range("C16") = 1 And Sheets("Temp").Range("B16") = 16 Then Sheets(Maand).Range("BJ" & result & ":BM" & result) = "x"
If Sheets("Temp").Range("C17") = 1 And Sheets("Temp").Range("B17") = 17 Then Sheets(Maand).Range("BN" & result & ":BQ" & result) = "x"
If Sheets("Temp").Range("C18") = 1 And Sheets("Temp").Range("B18") = 18 Then Sheets(Maand).Range("BR" & result & ":BU" & result) = "x"
If Sheets("Temp").Range("C19") = 1 And Sheets("Temp").Range("B19") = 19 Then Sheets(Maand).Range("BV" & result & ":BY" & result) = "x"
If Sheets("Temp").Range("C20") = 1 And Sheets("Temp").Range("B20") = 20 Then Sheets(Maand).Range("BZ" & result & ":CC" & result) = "x"
If Sheets("Temp").Range("C21") = 1 And Sheets("Temp").Range("B21") = 21 Then Sheets(Maand).Range("CD" & result & ":CG" & result) = "x"
If Sheets("Temp").Range("C22") = 1 And Sheets("Temp").Range("B22") = 22 Then Sheets(Maand).Range("CH" & result & ":CK" & result) = "x"
If Sheets("Temp").Range("C23") = 1 And Sheets("Temp").Range("B23") = 23 Then Sheets(Maand).Range("CL" & result & ":CO" & result) = "x"
If Sheets("Temp").Range("C24") = 1 And Sheets("Temp").Range("B24") = 24 Then Sheets(Maand).Range("CP" & result & ":CS" & result) = "x"
If Sheets("Temp").Range("C25") = 1 And Sheets("Temp").Range("B25") = 25 Then Sheets(Maand).Range("CT" & result & ":CW" & result) = "x"
If Sheets("Temp").Range("C26") = 1 And Sheets("Temp").Range("B26") = 26 Then Sheets(Maand).Range("CX" & result & ":DA" & result) = "x"
If Sheets("Temp").Range("C27") = 1 And Sheets("Temp").Range("B27") = 27 Then Sheets(Maand).Range("DB" & result & ":DE" & result) = "x"
If Sheets("Temp").Range("C28") = 1 And Sheets("Temp").Range("B28") = 28 Then Sheets(Maand).Range("DF" & result & ":DI" & result) = "x"
If Sheets("Temp").Range("C29") = 1 And Sheets("Temp").Range("B29") = 29 Then Sheets(Maand).Range("DJ" & result & ":DM" & result) = "x"
If Sheets("Temp").Range("C30") = 1 And Sheets("Temp").Range("B30") = 30 Then Sheets(Maand).Range("DN" & result & ":DQ" & result) = "x"
If Sheets("Temp").Range("C31") = 1 And Sheets("Temp").Range("B31") = 31 Then Sheets(Maand).Range("DR" & result & ":DU" & result) = "x"
If Sheets("Temp").Range("C32") = 1 And Sheets("Temp").Range("B32") = 1 Then Sheets(Maand).Range("B" & result & ":E" & result) = "x"
If Sheets("Temp").Range("C33") = 1 And Sheets("Temp").Range("B33") = 2 Then Sheets(Maand).Range("F" & result & ":I" & result) = "x"
If Sheets("Temp").Range("C34") = 1 And Sheets("Temp").Range("B34") = 3 Then Sheets(Maand).Range("J" & result & ":M" & result) = "x"
If Sheets("Temp").Range("C35") = 1 And Sheets("Temp").Range("B35") = 4 Then Sheets(Maand).Range("N" & result & ":Q" & result) = "x"
If Sheets("Temp").Range("C36") = 1 And Sheets("Temp").Range("B36") = 5 Then Sheets(Maand).Range("R" & result & ":U" & result) = "x"
If Sheets("Temp").Range("C37") = 1 And Sheets("Temp").Range("B37") = 6 Then Sheets(Maand).Range("V" & result & ":Y" & result) = "x"
If Sheets("Temp").Range("C38") = 1 And Sheets("Temp").Range("B38") = 7 Then Sheets(Maand).Range("Z" & result & ":AC" & result) = "x"
If Sheets("Temp").Range("C39") = 1 And Sheets("Temp").Range("B39") = 8 Then Sheets(Maand).Range("AD" & result & ":AG" & result) = "x"
If Sheets("Temp").Range("C40") = 1 And Sheets("Temp").Range("B40") = 9 Then Sheets(Maand).Range("AH" & result & ":AK" & result) = "x"
If Sheets("Temp").Range("C41") = 1 And Sheets("Temp").Range("B41") = 10 Then Sheets(Maand).Range("AL" & result & ":AO" & result) = "x"
If Sheets("Temp").Range("C42") = 1 And Sheets("Temp").Range("B42") = 11 Then Sheets(Maand).Range("AP" & result & ":AS" & result) = "x"
If Sheets("Temp").Range("C43") = 1 And Sheets("Temp").Range("B43") = 12 Then Sheets(Maand).Range("AT" & result & ":AW" & result) = "x"
If Sheets("Temp").Range("C44") = 1 And Sheets("Temp").Range("B44") = 13 Then Sheets(Maand).Range("AX" & result & ":BA" & result) = "x"
If Sheets("Temp").Range("C45") = 1 And Sheets("Temp").Range("B45") = 14 Then Sheets(Maand).Range("BB" & result & ":BE" & result) = "x"
If Sheets("Temp").Range("C46") = 1 And Sheets("Temp").Range("B46") = 15 Then Sheets(Maand).Range("BF" & result & ":BI" & result) = "x"
If Sheets("Temp").Range("C47") = 1 And Sheets("Temp").Range("B47") = 16 Then Sheets(Maand).Range("BJ" & result & ":BM" & result) = "x"
If Sheets("Temp").Range("C48") = 1 And Sheets("Temp").Range("B48") = 17 Then Sheets(Maand).Range("BN" & result & ":BQ" & result) = "x"
If Sheets("Temp").Range("C49") = 1 And Sheets("Temp").Range("B49") = 18 Then Sheets(Maand).Range("BR" & result & ":BU" & result) = "x"
If Sheets("Temp").Range("C50") = 1 And Sheets("Temp").Range("B50") = 19 Then Sheets(Maand).Range("BV" & result & ":BY" & result) = "x"
If Sheets("Temp").Range("C51") = 1 And Sheets("Temp").Range("B51") = 20 Then Sheets(Maand).Range("BZ" & result & ":CC" & result) = "x"
If Sheets("Temp").Range("C52") = 1 And Sheets("Temp").Range("B52") = 21 Then Sheets(Maand).Range("CD" & result & ":CG" & result) = "x"
If Sheets("Temp").Range("C53") = 1 And Sheets("Temp").Range("B53") = 22 Then Sheets(Maand).Range("CH" & result & ":CK" & result) = "x"
If Sheets("Temp").Range("C54") = 1 And Sheets("Temp").Range("B54") = 23 Then Sheets(Maand).Range("CL" & result & ":CO" & result) = "x"
If Sheets("Temp").Range("C55") = 1 And Sheets("Temp").Range("B55") = 24 Then Sheets(Maand).Range("CP" & result & ":CS" & result) = "x"
If Sheets("Temp").Range("C56") = 1 And Sheets("Temp").Range("B56") = 25 Then Sheets(Maand).Range("CT" & result & ":CW" & result) = "x"
If Sheets("Temp").Range("C57") = 1 And Sheets("Temp").Range("B57") = 26 Then Sheets(Maand).Range("CX" & result & ":DA" & result) = "x"
If Sheets("Temp").Range("C58") = 1 And Sheets("Temp").Range("B58") = 27 Then Sheets(Maand).Range("DB" & result & ":DE" & result) = "x"
If Sheets("Temp").Range("C59") = 1 And Sheets("Temp").Range("B59") = 28 Then Sheets(Maand).Range("DF" & result & ":DI" & result) = "x"
If Sheets("Temp").Range("C60") = 1 And Sheets("Temp").Range("B60") = 29 Then Sheets(Maand).Range("DJ" & result & ":DM" & result) = "x"
End Sub

I hope you can help me out.

Thanx

Delftsblauw
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Yes there is:p that code...lol
Code:
Sub Januari1()
Dim Medewerker As String: Medewerker = Verlof.ComboBox1.Value
Dim result As Integer: result = Application.WorksheetFunction.VLookup(Medewerker, Sheets("Januari").Range("A:DV"), 126, False)
Dim col As Integer: col = 2
For i = 1 To 60
If Sheets("Temp").Cells(i, 3) = 1 And Sheets("Temp").Cells(1, 2) = 1 Then
    Sheets("Januari").Range(Cells(result, col), Cells(result, col + 3)) = "x"
    col = col + 4
End If
End Sub

ps:'result' is changed to an integer as you use it as a rownumber
 
Upvote 0
Hi

Welcome to the MrExcel Forum.

Yes and shorter still!

Code:
Sub Januari1()
Dim Medewerker As String, Maand As String
Dim Cofs As Long, result As Long
Dim cell As Range

Medewerker = Verlof.ComboBox1.Value
Maand = "Januari"

result = Application.WorksheetFunction.VLookup(Medewerker, Sheets(Maand).Range("A:DV"), 126, False)

For Each cell In Sheets("Temp").Range("C1:C60")

If cell.row < 32 Then
    Cofs = (cell.row - 1) * 4
    If cell.Offset(, -1).Value = cell.row And cell.Value = 1 Then Sheets(Maand).Range("B" & result).Offset(, Cofs).Resize(, 4) = Array("x", "x", "x", "x")
Else
    Cofs = (cell.row - 32) * 4
    If cell.Offset(, -1).Value =  cell.row - 31 And cell.Value = 1 Then Sheets(Maand).Range("B" & result).Offset(, Cofs).Resize(, 4) = Array("x", "x", "x", "x")
End If

Next

End Sub

@Dendro You have omitted to note that the test on Column B reverts at row 32.

hth
 
Last edited:
Upvote 0
Seems like i did, oops! Lucky that you didn't:p
I haven't used 'array' yet, seems like i should check it out.
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top