Results 1 to 8 of 8

Code generating wrong values when run for multiple times (w.r.t previous solved thread)

Threaded View

Asad Mir Code generating wrong values... 06-20-2020, 04:09 AM
nankw83 Re: Code generating wrong... 06-20-2020, 04:24 AM
huuthang_bd Re: Code generating wrong... 06-20-2020, 04:30 AM
jindon Re: Code generating wrong... 06-20-2020, 04:33 AM
Asad Mir Re: Code generating wrong... 06-20-2020, 06:06 AM
torachan Re: Code generating wrong... 06-20-2020, 04:33 AM
Asad Mir Re: Code generating wrong... 06-20-2020, 05:53 AM
Asad Mir Re: Code generating wrong... 06-20-2020, 06:07 AM
  1. #1
    Registered User
    Join Date
    07-13-2019
    Location
    Mansehra, Pakistan
    MS-Off Ver
    2010
    Posts
    46

    Code generating wrong values when run for multiple times (w.r.t previous solved thread)

    Hello Everyone!

    Kindly refer to http://www.excelforum.com/excel-prog...r-methods.html

    When i run following code on the worksheet i attached, it produces correct results, i.e. replacing the whole dates with only "Day" for whole column untill lastrow.
    But, it reduces the "Day" by 1 in "Posting Date" column each time when i run the code again.
    For example after running the code for first time if the value was "1", running it for 2nd time produces 31, running it again would bring 30, and so on.
    Why is it reducing the value by 1 each time?

    Sub abc_1()
        Dim i As Long, rws As Long, tbl
        With Sheets("Sheet1")
            rws = .Cells(.Rows.Count, "D").End(xlUp).Row
            tbl = .Range("D2:D" & rws).Value
        End With
        rws = rws - 1
        For i = 1 To rws
            tbl(i, 1) = Day(tbl(i, 1)) 'Format(tbl(i, 1), "d")
        Next
        With Sheets("Sheet1").Range("D2:D" & rws + 1)
            .NumberFormat = "General"
            .Value = tbl
        End With
        tbl = Empty
    End Sub
    I am also attaching the sheet.

    Thanking in advance
    Attached Files Attached Files
    Last edited by Asad Mir; 06-20-2020 at 04:27 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Google Sheets - Generating a Sequential list based on previous values
    By lalalalalala in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 9
    Last Post: 12-13-2019, 07:05 AM
  2. [SOLVED] VBA to find in multiple sheets and place near match. Previous thread: Inventory VBA
    By baxius in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-14-2019, 10:46 AM
  3. [SOLVED] Link of thread "Mark thread as solved" Sticky
    By ImranBhatti in forum Suggestions for Improvement
    Replies: 2
    Last Post: 02-14-2017, 08:31 AM
  4. [SOLVED] Follow up error message from previous solved thread
    By RachelMads02 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 05-16-2016, 04:08 PM
  5. [SOLVED] Uable to change the title of my thread; [SOLVED] Textbox use with numerical values
    By rodalsa1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-09-2015, 09:37 AM
  6. Replies: 4
    Last Post: 01-18-2012, 09:55 PM
  7. [SOLVED] [SOLVED] Delete row containing all previous values.
    By mohd21uk via OfficeKB.com in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 05-10-2006, 09:00 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1