Forum

Excel - VBA: Code i...
 
Notifications
Clear all

Excel - VBA: Code is generating unexpected numbers (0)

2 Posts
2 Users
0 Reactions
52 Views
(@tana20)
Posts: 1
New Member
Topic starter
 

Hi All,

I really need help on this 🙁

This code is adding extra zeros in column D for no apparent reason; What part of the code is doing that?

Code: https://pastebin.com/ccpqPJdz

last = Range("B" & Rows.Count).End(xlUp).Row 'Insert 3 columns on left. Add information in Row 1, add data in column D. Columns("A:A").Select Selection.Insert Shift:=xlToRight Columns("A:A").Select Selection.Insert Shift:=xlToRight Columns("A:A").Select Selection.Insert Shift:=xlToRight Columns("E:E").Copy Destination:=Columns("C:C") Columns("E:E").Select Selection.Delete Shift:=xlToLeft Range("D2:D2" & last).Select Selection.SpecialCells(xlCellTypeBlanks).Select Selection.FormulaR1C1 = "=R[-1]C[6]" Columns("D").Copy Columns("D").PasteSpecial xlPasteValues Range("D1") = Time Range("D1").NumberFormat = "h:mm:ss" Input: input.png Output: output.png
 
Posted : 26/11/2020 11:48 pm
(@purfleet)
Posts: 412
Reputable Member
 

Please add a workbook and not pictures! it means that we have to waste time recreating a workbook

Range("D2:D2" & last).Select is the issue - last is 3 (number of rows) and this is being appended to D2:D2, so you are selecting range D2:D23. 
 
Posted : 27/11/2020 1:35 am
Share: