• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Fill Missing Months using VBA...what are the steps?

PP3321

Active Member
Dear Chandoo Community,
Thank you always for your help and guidance...
Today I have 1 question regarding VBA...

Using VBA, I want to:

1) fill missing month
2) take the value if it is different from previous cell.

Creating a column of months is OK,
but I do not know how to take the value if it is different from previous cell...

I would be extremely grateful if somebody could give me guidance on how to approach this problem...

Thanking you in advance...

What I want to achieve.PNG
 

Attachments

  • Chandoo Forum.xlsx
    15.9 KB · Views: 3
@vletm
Thank you so much but this is a very difficult code for me, especially entering the status part. I think it is difficult because there are many variables and I get confused :) I looked at each line and try to figure out what it is doing...

Code:
'starting row is set
y = 7
y1 = 6

        'Get First Value
        Do
            chk_1 = .Cells(y, 3)
            If chk_1 <> Empty Then
                yc = y - 1
               
                'Get Next Value
                Do
                    yc = yc + 1
                    chk_2 = .Cells(yc, 3)
                Loop Until chk_2 <> chk_1 Or chk_2 = Empty
               
                'Define row number of first Value
                Do
                    y1 = y1 + 1
                Loop Until (.Cells(y, 1) = .Cells(y1, 5) And Left(.Cells(y, 2), 3) = .Cells(y1, 6)) Or y1 > y_max
                y2 = y1 - 1
               
                'Define row number of second value
                Do
                    y2 = y2 + 1
                Loop Until (.Cells(yc, 1) = .Cells(y2, 5) And Left(.Cells(yc, 2), 3) = .Cells(y2, 6)) Or y2 > y_max
               
                'Enter Values between 2 row numbers
                If yy <= y_max Then
                    For yyy = y1 To y2 - 1
                        .Cells(yyy, 7) = chk_1
                    Next yyy
                End If
            End If
           
          'repeat for next value
            y = y + 1
        Loop Until .Cells(y, 1) = Empty
 
Yes..
I add some 'notes' and ideas with version.
It would be 'easier' to see what happens
if You would run that code row-by-row and
even better if You would see with which cell the code is working.
This is one possible ...
 

Attachments

  • Chandoo Forum.xlsb
    49.7 KB · Views: 4
@vletm,
1.Thank you so much for the notes...!!
2. Thank you also for your advice. I did not think of running code by code.
I googled and found that I can do F9 to add breaks...
I will also use immediate window to see the value of each variable...

Thank you!!!!!!
 
Thanks..
I meant this kind of
'even better if You would see with which cell the code is working.'
read cell B1 note
 

Attachments

  • Chandoo Forum.xlsb
    60.3 KB · Views: 7
@vletm wow! Thank you so much for that step-by step animation!!! I do not have words to tell you how thankful I am!!!!!
 
Back
Top