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

Tana20 21 Reputation points
2020-11-26T03:37:02.633+00:00

Hi All,

I don't understand why the code below adds those extra zeros in column D; What am I doing wrong?

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:
42846-12020-11-25-20-50-49.png

Output:
42778-22020-11-25-20-53-01.png

Community Center Not monitored
0 comments No comments
{count} votes

Accepted answer
  1. Emily Hua-MSFT 27,796 Reputation points
    2020-11-26T07:58:24.953+00:00

    @Tana20
    As threads with tag "office-excel-itpro" focus on general issues of Excel client, but your issue is about VBA code, which is not supported on Q&A forum.

    To better help you, I would suggest you post a new question on the forum below.
    Excel for Developers

    Thanks for your understanding.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.