Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:46:00+00:00 2026-06-11T03:46:00+00:00

I created this macro to correct an error (to fill blank created by Feb

  • 0

I created this macro to correct an error (to fill blank created by Feb 29 in non-leap years)i have been facing problem in stopping the Do Until loop.

the macro does what it is supposed to do but it is not working as supposed to with Do Until ActiveSheet.Cells(3, x) = "2012" i want it to stop when cell (3,x) is 2012

Sub Feb_CORRECTION()
Dim i, x As Integer
Dim year
Dim leapyear

Range("c64").Select
x = 3
Do Until ActiveSheet.Cells(3, x) = "2012"
year = ActiveSheet.Cells(3, x)
leapyear = year Mod 4
If leapyear > 0 Then
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Cut
ActiveCell.Offset(-1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 1).Select
Else
ActiveCell.Offset(0, 1).Select
x = x + 1
End If
Loop

End Sub

thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:46:02+00:00Added an answer on June 11, 2026 at 3:46 am

    Your loop is set to exit if the value in row 3 in column x is “2012”.

    You initialize x to 3, then check to see if the year in row 3 is a leap year. You only increment x if it is, so unless the year in column “C” is a leap year, x will never get incremented.

    Try this instead:

    Sub Feb_CORRECTION()
    Dim i As Integer
    Dim x As Integer
    
    Dim year As Integer
    Dim leapyear As Integer
    
        Range("c64").Select
        x = 3
    
        Do Until ActiveSheet.Cells(3, x) = "2012"
            year = ActiveSheet.Cells(3, x)
            leapyear = year Mod 4
    
            If leapyear > 0 Then
                Range(ActiveCell, ActiveCell.End(xlDown)).Select
                Selection.Cut
                ActiveCell.Offset(-1, 0).Select
                ActiveSheet.Paste
                ActiveCell.Offset(1, 1).Select
            Else
                ActiveCell.Offset(0, 1).Select
            End If
    
            ' increment x regardless of leap year status
            x = x + 1
        Loop
    
    End Sub
    

    You also have several variables declared as variants, which is a bad idea unless you have a very specific reason for using them. Variants can lead to bugs that are very hard to track down. I’ve fixed that in the snippet above.

    Note that this line in your code is declaring i as a variant and x as an integer:

    Dim i, x As Integer
    

    You’ve also declared both year and leapyear as variants. They should probably be integers instead.

    Final comment: format your code with indents. It is much easier to understand what it is doing if formatted correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ever since I created this Rails 3.2.3 project to use MiniTest, I have been
I have created a simple excel worksheet. This is my macro code: Sub MyMacro()
I have just created this table: create table dbo.OrderTypes ( ID smallint primary key
I have created this simple program to learn shared_ptr using namespace std; #define Yes
I have created a macro to make reserve memory for my strings in C
I have this macro code, which allows me to define both a C enum
I created this macro to replace a specific word with another word in the
I have created the macro below in Microsoft Excel 2003 on a windows XP
I created this report in iReport Professional 4.5.1 and deployed it to JasperReports Server
I created this program: #include <iostream> #include <fstream> using namespace std; int main ()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.