VBA step by step different result than running macro

Strooprover

New Member
Joined
Jul 21, 2017
Messages
25
Hi,

I'm testing my code below. However when I run it step by step it works perfectly fine. When I run the macro in total, however, I get some wrong results. I know that the script below is way to long for you guys so I'm not assuming someone can help me with this specific code. But maybe some general tips so I can search myself where I'm going wrong.

Code:
[FONT=arial]Do Until counter = ws1.Range("F" & u)[/FONT]
[FONT=arial]For i = RGX To Range("C" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]ws.Cells(i, 3).Value = ws.Cells(i, 3).Value - 5[/FONT]
[FONT=arial]counter = counter - 5[/FONT]
[FONT=arial]If counter = ws1.Range("F" & u) Then[/FONT]
[FONT=arial]Exit Do[/FONT]
[FONT=arial]End If[/FONT]

The strange thing is that for the part above he seems to count the right range of C. But when I run it complete it takes one Row to much. At least at the last "u".

Some tips would be very appreciated. Thanks in advance!!


Code:
[FONT=arial]Sub OGPREP()[/FONT]
[FONT=arial]    Rows("1:2").Select[/FONT]
[FONT=arial]    Selection.Delete Shift:=xlUp[/FONT]
[FONT=arial]    [/FONT]
[FONT=arial]    Range("A2").Select[/FONT]
[FONT=arial]    Range(Selection, Selection.End(xlDown)).Select[/FONT]
[FONT=arial]    Selection.NumberFormat = "dd/mm/yy;@"[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]i = Range("A" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]For x = 2 To i[/FONT]
[FONT=arial]If Cells(x, 7) = "Product;" Or Cells(x, 7) = "" Then[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Else[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Cells(x, 7).Select[/FONT]
[FONT=arial]Selection.EntireRow.Delete[/FONT]
[FONT=arial]x = x - 1[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]Next x[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Columns("B:N").EntireColumn.<wbr>Delete[/FONT]
[FONT=arial]Columns("C:I").EntireColumn.<wbr>Delete[/FONT]
[FONT=arial]Columns("D:P").EntireColumn.<wbr>Delete[/FONT]
[FONT=arial]    Columns("C:C").Select[/FONT]
[FONT=arial]    Selection.Insert Shift:=xlToRight, CopyOrigin:=<wbr>xlFormatFromLeftOrAbove[/FONT]
[FONT=arial]    Columns("A:A").Copy Destination:=Columns("C:C")[/FONT]
[FONT=arial]Columns("A:A").EntireColumn.<wbr>Delete[/FONT]
[FONT=arial]    Columns("A:C").EntireColumn.<wbr>AutoFit[/FONT]
[FONT=arial]    [/FONT]
[FONT=arial]i = Range("A" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]  Columns("B:B").Copy Destination:=Columns("D:D")[/FONT]
[FONT=arial]    Range("D2").Select[/FONT]
[FONT=arial]  ActiveCell.FormulaR1C1 = "=ROUNDDOWN(RC[-2],0)"[/FONT]
[FONT=arial]    Range("D2").Select[/FONT]
[FONT=arial]    Selection.AutoFill Destination:=Range("D2:D" & i)[/FONT]
[FONT=arial]    Range("D2:D" & i).Select[/FONT]
[FONT=arial]    Selection.NumberFormat = "dd/mm/yy;@"[/FONT]
[FONT=arial]    Selection.Copy[/FONT]
[FONT=arial]    Range("B2").Select[/FONT]
[FONT=arial]    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _[/FONT]
[FONT=arial]        :=False, Transpose:=False[/FONT]
[FONT=arial]Columns("D:D").EntireColumn.<wbr>Delete[/FONT]
[FONT=arial]    [/FONT]
[FONT=arial]    Range("B2").Select[/FONT]
[FONT=arial]    Range(Selection, Selection.End(xlDown)).Copy Destination:=Range("E2")[/FONT]
[FONT=arial]    Columns("E:E").Select[/FONT]
[FONT=arial]    ActiveSheet.Range("$E$1:$E$<wbr>165").RemoveDuplicates Columns:=1, Header:=xlNo[/FONT]
[FONT=arial]    Range("E1") = "Datum"[/FONT]
[FONT=arial]    Range("F1") = "Totaal gewicht"[/FONT]
[FONT=arial]    Columns("F:F").AutoFit[/FONT]
[FONT=arial]    [/FONT]
[FONT=arial]   Sheets("Blad1").Name = "Blad2"[/FONT]
[FONT=arial]    Sheets("Globus !").Name = "Blad1"[/FONT]
[FONT=arial]    [/FONT]
[FONT=arial]MsgBox "Put totalweight for corresponding date", vbOKOnly[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]lastrowE = Range("E" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]ActiveSheet.Buttons.Add Range("E" & lastrowE).Left, Range("E" & lastrowE + 1).Top, Range("A1:A3").Width, Range("A1:C3").Height[/FONT]
[FONT=arial]ActiveSheet.Buttons.Select[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]With Selection[/FONT]
[FONT=arial].OnAction = "Naklikken"[/FONT]
[FONT=arial].Characters.Text = "All weights fixed?"[/FONT]
[FONT=arial].Font.Bold = True[/FONT]
[FONT=arial]End With[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]End Sub[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Sub Naklikken()[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]answer = MsgBox("All weights fixed?", vbYesNo + vbQuestion)[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]If answer = vbNo Then[/FONT]
[FONT=arial]Cells(2, 6).Select[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Else[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Dim ws1 As Worksheet[/FONT]
[FONT=arial]Dim ws2 As Worksheet[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Set ws1 = Sheets("Blad1")[/FONT]
[FONT=arial]Set ws = Sheets("Blad2")[/FONT]
[FONT=arial]RGX = 1[/FONT]
[FONT=arial]RG = 1[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]For u = 2 To ws1.Range("E" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]counter = 0[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]For x = 2 To ws1.Range("A" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]If ws1.Cells(x, 2) = ws1.Cells(u, 5) Then[/FONT]
[FONT=arial]ws1.Cells(x, 1).Copy Destination:=ws.Range("A" & RG)[/FONT]
[FONT=arial]ws1.Cells(x, 2).Copy Destination:=ws.Range("B" & RG)[/FONT]
[FONT=arial]ws1.Cells(x, 3).Copy Destination:=ws.Range("C" & RG)[/FONT]
[FONT=arial]  counter = counter + ws.Range("C" & RG).Value[/FONT]
[FONT=arial]   RG = RG + 1[/FONT]
[FONT=arial]  [/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]Next x[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]If counter < ws1.Range("F" & u) Then[/FONT]
[FONT=arial]Do Until counter = ws1.Range("F" & u)[/FONT]
[FONT=arial]For i = RGX To Range("B" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]ws.Cells(i, 3).Value = ws.Cells(i, 3).Value + 5[/FONT]
[FONT=arial]counter = counter + 5[/FONT]
[FONT=arial]If counter = ws1.Range("F" & u) Then[/FONT]
[FONT=arial]Exit Do[/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Next i[/FONT]
[FONT=arial]Loop[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Else[/FONT]
[FONT=arial]Do Until counter = ws1.Range("F" & u)[/FONT]
[FONT=arial]For i = RGX To Range("C" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]ws.Cells(i, 3).Value = ws.Cells(i, 3).Value - 5[/FONT]
[FONT=arial]counter = counter - 5[/FONT]
[FONT=arial]If counter = ws1.Range("F" & u) Then[/FONT]
[FONT=arial]Exit Do[/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Next i[/FONT]
[FONT=arial]Loop[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]arow = ws.Range("A" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]RGX = RG[/FONT]
[FONT=arial]Next u[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Sheets("Blad2").Select[/FONT]
[FONT=arial]Range("A1").Select[/FONT]
[FONT=arial]ActiveCell.EntireRow.Insert[/FONT]
[FONT=arial]ws.Range("A1") = "Straat"[/FONT]
[FONT=arial]ws.Range("B1") = "Datum"[/FONT]
[FONT=arial]ws.Range("C1") = "Gewicht"[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]    Columns("A:C").Select[/FONT]
[FONT=arial]    Selection.Copy[/FONT]
[FONT=arial]    Sheets("Blad1").Select[/FONT]
[FONT=arial]    Columns("A:C").Select[/FONT]
[FONT=arial]    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _[/FONT]
[FONT=arial]        :=False, Transpose:=False[/FONT]
[FONT=arial]Sheets("Blad2").Cells.<wbr>ClearContents[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Sheets("Blad1").Columns("E:G")<wbr>.Clear[/FONT]
[FONT=arial]Sheets("Blad1").Buttons.Delete[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Dim rowx As Long[/FONT]
[FONT=arial]Dim lastrow As Integer[/FONT]
[FONT=arial]Dim ws3 As Worksheet[/FONT]
[FONT=arial]Dim ws4 As Worksheet[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Set ws3 = Sheets("Blad1")[/FONT]
[FONT=arial]Set ws4 = Sheets("Blad2")[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Sheets("Blad1").Select[/FONT]
[FONT=arial]    Range("A2").Select[/FONT]
[FONT=arial]    Range(Selection, Selection.End(xlDown)).Select[/FONT]
[FONT=arial]    Selection.Copy[/FONT]
[FONT=arial]    Sheets("Blad2").Select[/FONT]
[FONT=arial]    Range("H1").Select[/FONT]
[FONT=arial]    ActiveSheet.Paste[/FONT]
[FONT=arial]    Application.CutCopyMode = False[/FONT]
[FONT=arial]    Range("H1").Select[/FONT]
[FONT=arial]    Range(Selection, Selection.End(xlDown)).Select[/FONT]
[FONT=arial]    ActiveSheet.Range("H:H").<wbr>RemoveDuplicates Columns:=1, Header:=xlNo[/FONT]
[FONT=arial]    ActiveWindow.SmallScroll Down:=-24[/FONT]
[FONT=arial]  [/FONT]
[FONT=arial]lastrow = Worksheets("Blad2").Range("H1"<wbr>).End(xlDown).Row[/FONT]
[FONT=arial]Worksheets("Blad2").Range("F1:<wbr>F" & lastrow).FormulaR1C1 = "=COUNTIF(Blad1!C[-5],Blad2!<wbr>RC[+2])"[/FONT]
[FONT=arial]Worksheets("Blad2").Range("G1:<wbr>G" & lastrow).FormulaR1C1 = "=RC[-1]+4"[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]rowx = 1[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]For i = 1 To ws4.Range("H" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]rowx = rowx + Range("G" & i).Value[/FONT]
[FONT=arial]  Range("B" & rowx).Value = Range("H" & i + 1).Value[/FONT]
[FONT=arial]  Range("B" & rowx).Name = ("Cont" & i + 1)[/FONT]
[FONT=arial]  [/FONT]
[FONT=arial]Next i[/FONT]
[FONT=arial]Range("B1").Value = Range("H1")[/FONT]
[FONT=arial]Range("B1").Name = "Cont1"[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]For i = 1 To ws4.Range("H" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]ws4.Select[/FONT]
[FONT=arial]Range("Cont" & i).Select[/FONT]
[FONT=arial]ActiveCell.Offset(0, -1).Value = "Product"[/FONT]
[FONT=arial]ActiveCell.Offset(1, 0).Value = "Weight"[/FONT]
[FONT=arial]ActiveCell.Offset(1, 1).Value = "Costs per product"[/FONT]
[FONT=arial]ActiveCell.Offset(1, 2).Value = "Extra costs"[/FONT]
[FONT=arial]ActiveCell.Offset(1, 3).Value = "Total costs"[/FONT]
[FONT=arial]ActiveCell.Offset(1, -1).Value = "Date"[/FONT]
[FONT=arial]ActiveCell.Offset(1, 0).Value = "Weight"[/FONT]
[FONT=arial]ActiveCell.Offset(2, -1).Select[/FONT]
[FONT=arial]a = ActiveCell.Row[/FONT]
[FONT=arial]pr = 0[/FONT]
[FONT=arial]mycount = 0[/FONT]
[FONT=arial]For RI = 2 To ws3.Range("A" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=arial]If ws3.Cells(RI, 1) = Range("Product" & i).Value Then[/FONT]
[FONT=arial]ws4.Cells(a + pr, 1) = ws3.Cells(RI, 2)[/FONT]
[FONT=arial]ws4.Cells(a + pr, 2) = ws3.Cells(RI, 3)[/FONT]
[FONT=arial]ws4.Cells(a + pr, 2).Select[/FONT]
[FONT=arial]Selection.NumberFormat = "0.00"[/FONT]
[FONT=arial]mycount = mycount + ws4.Cells(a + pr, 2)[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]ws4.Cells(a + pr, 1).Select[/FONT]
[FONT=arial] Selection.NumberFormat = "m/d/yyyy"[/FONT]
[FONT=arial]pr = pr + 1[/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Next RI[/FONT]
[FONT=arial]ws4.Cells(a + pr, 1).Value = "Total"[/FONT]
[FONT=arial]ws4.Cells(a + pr, 1).Select[/FONT]
[FONT=arial] With Selection[/FONT]
[FONT=arial]        .HorizontalAlignment = xlRight[/FONT]
[FONT=arial]         .VerticalAlignment = xlBottom[/FONT]
[FONT=arial]           End With[/FONT]
[FONT=arial]    Selection.Font.Bold = True[/FONT]
[FONT=arial]    [/FONT]
[FONT=arial]    ws4.Cells(a + pr, 2).Value = mycount[/FONT]
[FONT=arial]    ws4.Cells(a + pr, 2).Select[/FONT]
[FONT=arial]  Selection.NumberFormat = "0.00"[/FONT]
[FONT=arial]    [/FONT]
[FONT=arial]   sumval = Range("F" & i).Value[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]    ws4.Cells(a + pr, 5).FormulaR1C1 = "=SUM(R[" & -sumval & "]C:R[-1]C)"[/FONT]
[FONT=arial]        ws4.Cells(a + pr, 5).Select[/FONT]
[FONT=arial]        Selection.Style = "Currency"[/FONT]
[FONT=arial]    [/FONT]
[FONT=arial]Next i[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Dim tabel As String[/FONT]
[FONT=arial]tabel = ws4.Range("A1").Value[/FONT]
[FONT=arial]For x = 1 To 1000[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]If ws4.Cells(x, 1) = tabel Then[/FONT]
[FONT=arial]ws4.Cells(x, 1).Select[/FONT]
[FONT=arial]ActiveCell.Range("A1:E1").<wbr>Select[/FONT]
[FONT=arial]Range(Selection, Selection.End(xlDown)).Select[/FONT]
[FONT=arial]    Selection.Borders(<wbr>xlDiagonalDown).LineStyle = xlNone[/FONT]
[FONT=arial]    Selection.Borders(<wbr>xlDiagonalUp).LineStyle = xlNone[/FONT]
[FONT=arial]        With Selection.Borders(xlEdgeLeft)[/FONT]
[FONT=arial]        .LineStyle = xlContinuous[/FONT]
[FONT=arial]        .ColorIndex = 0[/FONT]
[FONT=arial]        .TintAndShade = 0[/FONT]
[FONT=arial]        .Weight = xlThin[/FONT]
[FONT=arial]    End With[/FONT]
[FONT=arial]    With Selection.Borders(xlEdgeTop)[/FONT]
[FONT=arial]        .LineStyle = xlContinuous[/FONT]
[FONT=arial]        .ColorIndex = 0[/FONT]
[FONT=arial]        .TintAndShade = 0[/FONT]
[FONT=arial]        .Weight = xlThin[/FONT]
[FONT=arial]    End With[/FONT]
[FONT=arial]    With Selection.Borders(<wbr>xlEdgeBottom)[/FONT]
[FONT=arial]        .LineStyle = xlContinuous[/FONT]
[FONT=arial]        .ColorIndex = 0[/FONT]
[FONT=arial]        .TintAndShade = 0[/FONT]
[FONT=arial]        .Weight = xlThin[/FONT]
[FONT=arial]    End With[/FONT]
[FONT=arial]    With Selection.Borders(xlEdgeRight)[/FONT]
[FONT=arial]        .LineStyle = xlContinuous[/FONT]
[FONT=arial]        .ColorIndex = 0[/FONT]
[FONT=arial]        .TintAndShade = 0[/FONT]
[FONT=arial]        .Weight = xlThin[/FONT]
[FONT=arial]    End With[/FONT]
[FONT=arial]    With Selection.Borders(<wbr>xlInsideVertical)[/FONT]
[FONT=arial]        .LineStyle = xlContinuous[/FONT]
[FONT=arial]        .ColorIndex = 0[/FONT]
[FONT=arial]        .TintAndShade = 0[/FONT]
[FONT=arial]        .Weight = xlThin[/FONT]
[FONT=arial]    End With[/FONT]
[FONT=arial]    With Selection.Borders(<wbr>xlInsideHorizontal)[/FONT]
[FONT=arial]        .LineStyle = xlContinuous[/FONT]
[FONT=arial]        .ColorIndex = 0[/FONT]
[FONT=arial]        .TintAndShade = 0[/FONT]
[FONT=arial]        .Weight = xlThin[/FONT]
[FONT=arial]    End With[/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]Next x[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Dim kosten As String[/FONT]
[FONT=arial]kosten = ws4.Range("C2").Value[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]i = 1[/FONT]
[FONT=arial]For x = 1 To 1000[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]keer = Range("F" & i).Value[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]If ws4.Cells(x, 3) = costsThen[/FONT]
[FONT=arial]ws4.Cells(x, 3).Select[/FONT]
[FONT=arial]ActiveCell.Offset(1, 0).Select[/FONT]
[FONT=arial]ActiveCell.Range("A1:A" & keer).Value = "€30,01"[/FONT]
[FONT=arial]ActiveCell.Range("A1:A" & keer).Value = CDec(ActiveCell.Value)[/FONT]
[FONT=arial]ActiveCell.Range("A1:A" & keer).NumberFormat = "$ #,##0.00"[/FONT]
[FONT=arial]i = i + 1[/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Next x[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Dim verwkosten As String[/FONT]
[FONT=arial]verwkosten = ws4.Range("D2").Value[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]i = 1[/FONT]
[FONT=arial]For x = 1 To 1000[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]keer = Range("F" & i).Value[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]If ws4.Cells(x, 4) = extra costs Then[/FONT]
[FONT=arial]ws4.Cells(x, 4).Select[/FONT]
[FONT=arial]ActiveCell.Offset(1, 0).Select[/FONT]
[FONT=arial]ActiveCell.Range("A1:A" & keer).Value = "€0,00"[/FONT]
[FONT=arial]ActiveCell.Range("A1:A" & keer).Value = CDec(ActiveCell.Value)[/FONT]
[FONT=arial]ActiveCell.Range("A1:A" & keer).NumberFormat = "$ #,##0.00"[/FONT]
[FONT=arial]i = i + 1[/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Next x[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Dim lr As Long[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]lr = ws4.Cells(Rows.Count, 3).End(xlUp).Row[/FONT]
[FONT=arial]For x = 1 To lr[/FONT]
[FONT=arial]    If Cells(x, 3).NumberFormat = "$ #,##0.00" Then[/FONT]
[FONT=arial]        Cells(x, 5) = Cells(x, 3) + Cells(x, 4)[/FONT]
[FONT=arial]    End If[/FONT]
[FONT=arial]Next x[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Dim ttl As String[/FONT]
[FONT=arial]ttl = "Totaal"[/FONT]
[FONT=arial]For x = 1 To 1000[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]If ws4.Cells(x, 1) = ttl Then[/FONT]
[FONT=arial]ws4.Cells(x, 5).Select[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]totsum = totsum + ws4.Cells(x, 5).Value[/FONT]
[FONT=arial]End If[/FONT]
[FONT=arial]Next x[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Totrij = Range("E" & Rows.Count).End(xlUp).Row + 2[/FONT]
[FONT=arial]Cells(Totrij, 5).Value = totsum[/FONT]
[FONT=arial]Cells(Totrij, 5).Select[/FONT]
[FONT=arial]  Selection.Style = "Currency"[/FONT]
[FONT=arial]Cells(Totrij, 4).Value = "Totale kosten"[/FONT]
[FONT=arial]Cells(Totrij, 4).Select[/FONT]
[FONT=arial] With Selection[/FONT]
[FONT=arial]        .HorizontalAlignment = xlRight[/FONT]
[FONT=arial]         .VerticalAlignment = xlBottom[/FONT]
[FONT=arial]           End With[/FONT]
[FONT=arial]    Selection.Font.Bold = True[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]    Columns("A:A").EntireColumn.<wbr>AutoFit[/FONT]
[FONT=arial]    Columns("E:E").EntireColumn.<wbr>AutoFit[/FONT]
[FONT=arial]    Columns("F:H").Select[/FONT]
[FONT=arial]    Selection.Delete Shift:=xlToLeft[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]End Sub[/FONT]
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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