Results 1 to 3 of 3

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

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    2

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

    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

    Code:
     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:
    Name:  input.jpg
Views: 141
Size:  17.9 KB

    Output:
    Name:  output.png
Views: 238
Size:  3.8 KB

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

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

    These lines

    Code:
     Range("D2:D2" & last).Select
     Selection.SpecialCells(xlCellTypeBlanks).Select
     Selection.FormulaR1C1 = "=R[-1]C[6]"
    must be the culprit.

    Btw, how did you get such '80s look of your screenshots? Is this some special filter in your favorite image editor?

    cheers,
    </wqw>

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    2

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

    Thanks, you are right the line Range("D2: D2" & last).Select is causing the issue, last = 3,

    Regarding the images, I didn't apply any filter I just uploaded them as png, they look normal on my pc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width