Create a checkpoint in a foreach statementHow to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?Find data cell value, move up one cell in column, find next data cell within a column and get next valueCreate Cells starting at date x and ending at date yExcel VBA: Having trouble understanding LoopsExcel VBA - Selection Routine'If … Then' statement with loopTranspose visible cells till last columnVBA IF statement Loop If values are equalExcel VBA macro to send emails to unique users in rangeHow can I add looping per 250 cells and offset the array?

Why doesn't a marching band have strings?

How to split an equation over two lines?

Intuitively, why does putting capacitors in series decrease the equivalent capacitance?

Fedora boot screen shows both Fedora logo and Lenovo logo. Why and How?

Is there any set of 2-6 notes that doesn't have a chord name?

What happens when your group is victim of a surprise attack but you can't be surprised?

Is adding a new player (or players) a DM decision, or a group decision?

Why is the Turkish president's surname spelt in Russian as Эрдоган, with г?

What reason would an alien civilization have for building a Dyson Sphere (or Swarm) if cheap Nuclear fusion is available?

How does a blind passenger not die, if driver becomes unconscious

Is there vegetarian astronaut?

When is it ok to add filler to a story?

Links to webpages in books

Why is the voltage measurement of this circuit different when the switch is on?

Was there ever a name for the weapons of the Others?

Should I hide continue button until tasks are completed?

What happens when I sacrifice a creature when my Teysa Karlov is on the battlefield?

Is this one of the engines from the 9/11 aircraft?

quadratic equation solving mistake

Distance Matrix (plugin) - QGIS

No IMPLICIT_CONVERSION warning in this query plan

What is the legal status of travelling with (unprescribed) methadone in your carry-on?

Should my manager be aware of private LinkedIn approaches I receive? How to politely have this happen?

Change CPU MHz from Registry



Create a checkpoint in a foreach statement


How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?Find data cell value, move up one cell in column, find next data cell within a column and get next valueCreate Cells starting at date x and ending at date yExcel VBA: Having trouble understanding LoopsExcel VBA - Selection Routine'If … Then' statement with loopTranspose visible cells till last columnVBA IF statement Loop If values are equalExcel VBA macro to send emails to unique users in rangeHow can I add looping per 250 cells and offset the array?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am writing a code that put an X in a cell depending on a offset cell value, for exemple if the offset cell has a value of 3, it will put an X in the cell and decrement the offset cell value, i want to save the location of that cell and start the next for each with it.



 For Each Cell In plage 
If (Cell.Offset(0, 1).Value <> 0) Then


If (Cell.Value <> "X") Then


Cell.Offset(0, 1).Value = Cell.Offset(0, 1).Value - 1

Cell.Value = "X"
Checkpoint = Cell.Address
Exit For

Else

Cell.Value = ""

GoTo NextStep

End If

Exit For

Else

Cell.Value = ""

End If

NextStep:

Next Cell


The problem i am having with the current code is it start the loop all over again while i want it to keep till the end of the lines, until all offset value are equal to 0.










share|improve this question




























    0















    I am writing a code that put an X in a cell depending on a offset cell value, for exemple if the offset cell has a value of 3, it will put an X in the cell and decrement the offset cell value, i want to save the location of that cell and start the next for each with it.



     For Each Cell In plage 
    If (Cell.Offset(0, 1).Value <> 0) Then


    If (Cell.Value <> "X") Then


    Cell.Offset(0, 1).Value = Cell.Offset(0, 1).Value - 1

    Cell.Value = "X"
    Checkpoint = Cell.Address
    Exit For

    Else

    Cell.Value = ""

    GoTo NextStep

    End If

    Exit For

    Else

    Cell.Value = ""

    End If

    NextStep:

    Next Cell


    The problem i am having with the current code is it start the loop all over again while i want it to keep till the end of the lines, until all offset value are equal to 0.










    share|improve this question
























      0












      0








      0








      I am writing a code that put an X in a cell depending on a offset cell value, for exemple if the offset cell has a value of 3, it will put an X in the cell and decrement the offset cell value, i want to save the location of that cell and start the next for each with it.



       For Each Cell In plage 
      If (Cell.Offset(0, 1).Value <> 0) Then


      If (Cell.Value <> "X") Then


      Cell.Offset(0, 1).Value = Cell.Offset(0, 1).Value - 1

      Cell.Value = "X"
      Checkpoint = Cell.Address
      Exit For

      Else

      Cell.Value = ""

      GoTo NextStep

      End If

      Exit For

      Else

      Cell.Value = ""

      End If

      NextStep:

      Next Cell


      The problem i am having with the current code is it start the loop all over again while i want it to keep till the end of the lines, until all offset value are equal to 0.










      share|improve this question














      I am writing a code that put an X in a cell depending on a offset cell value, for exemple if the offset cell has a value of 3, it will put an X in the cell and decrement the offset cell value, i want to save the location of that cell and start the next for each with it.



       For Each Cell In plage 
      If (Cell.Offset(0, 1).Value <> 0) Then


      If (Cell.Value <> "X") Then


      Cell.Offset(0, 1).Value = Cell.Offset(0, 1).Value - 1

      Cell.Value = "X"
      Checkpoint = Cell.Address
      Exit For

      Else

      Cell.Value = ""

      GoTo NextStep

      End If

      Exit For

      Else

      Cell.Value = ""

      End If

      NextStep:

      Next Cell


      The problem i am having with the current code is it start the loop all over again while i want it to keep till the end of the lines, until all offset value are equal to 0.







      excel vba






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 10:22









      Sonofliberty11Sonofliberty11

      51 bronze badge




      51 bronze badge






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Try the below (there are notes on the code). If you face difficulties let me know.



          Option Explicit

          Sub test()

          'In this example we assume that the data you want to loop appear in Column A

          Dim i As Long, Lastrow As Long
          Dim Checkpoint As Variant

          With ThisWorkbook.Worksheets("Sheet1") '<- Change sheet name if needed

          Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row '< -Fins the lastrow of the column you want to loop

          For i = 2 To Lastrow ' < -Start looping from row 2 to Lastrow fo the column

          If .Range("A" & i).Offset(0, 1).Value <> 0 Then '<- You are looping

          If .Range("A" & i).Value <> "X" Then

          .Range("A" & i).Offset(0, 1).Value = .Range("A" & i).Offset(0, 1).Value - 1

          .Range("A" & i).Value = .Range("A" & i).Value & "X"
          Checkpoint = .Range("A" & i).Address

          Else

          .Range("A" & i).Value = ""

          End If

          Else

          .Range("A" & i).Value = ""

          End If

          Next i

          End With

          End Sub





          share|improve this answer

























          • Thanks a lot for you code, i tried it and it worked, the problem is i want it to add one X each time i press the button

            – Sonofliberty11
            Mar 25 at 11:41











          • I have edited the answer. Could you please try again?

            – Error 1004
            Mar 25 at 12:32











          • I tried your eddited code, its better but it still put an X if he find a 0 in the offset cell, also i don't see the point of the checkpoint variable

            – Sonofliberty11
            Mar 25 at 15:06


















          0














          Is plage a range?



          If so, you could update it to start from the checkpoint and include all cells up to some lastCell for example.



          Something like:



          set plage=thisWorkbook.Worksheets("Your Worksheet").Range(checkpoint,lastCell)


          That way the next For-Each should start from your checkpoint.



          BTW if I understand correctly what you'e trying to do, I would suggest you replace cell.value="" with cell.clearContents






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55335623%2fcreate-a-checkpoint-in-a-foreach-statement%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Try the below (there are notes on the code). If you face difficulties let me know.



            Option Explicit

            Sub test()

            'In this example we assume that the data you want to loop appear in Column A

            Dim i As Long, Lastrow As Long
            Dim Checkpoint As Variant

            With ThisWorkbook.Worksheets("Sheet1") '<- Change sheet name if needed

            Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row '< -Fins the lastrow of the column you want to loop

            For i = 2 To Lastrow ' < -Start looping from row 2 to Lastrow fo the column

            If .Range("A" & i).Offset(0, 1).Value <> 0 Then '<- You are looping

            If .Range("A" & i).Value <> "X" Then

            .Range("A" & i).Offset(0, 1).Value = .Range("A" & i).Offset(0, 1).Value - 1

            .Range("A" & i).Value = .Range("A" & i).Value & "X"
            Checkpoint = .Range("A" & i).Address

            Else

            .Range("A" & i).Value = ""

            End If

            Else

            .Range("A" & i).Value = ""

            End If

            Next i

            End With

            End Sub





            share|improve this answer

























            • Thanks a lot for you code, i tried it and it worked, the problem is i want it to add one X each time i press the button

              – Sonofliberty11
              Mar 25 at 11:41











            • I have edited the answer. Could you please try again?

              – Error 1004
              Mar 25 at 12:32











            • I tried your eddited code, its better but it still put an X if he find a 0 in the offset cell, also i don't see the point of the checkpoint variable

              – Sonofliberty11
              Mar 25 at 15:06















            0














            Try the below (there are notes on the code). If you face difficulties let me know.



            Option Explicit

            Sub test()

            'In this example we assume that the data you want to loop appear in Column A

            Dim i As Long, Lastrow As Long
            Dim Checkpoint As Variant

            With ThisWorkbook.Worksheets("Sheet1") '<- Change sheet name if needed

            Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row '< -Fins the lastrow of the column you want to loop

            For i = 2 To Lastrow ' < -Start looping from row 2 to Lastrow fo the column

            If .Range("A" & i).Offset(0, 1).Value <> 0 Then '<- You are looping

            If .Range("A" & i).Value <> "X" Then

            .Range("A" & i).Offset(0, 1).Value = .Range("A" & i).Offset(0, 1).Value - 1

            .Range("A" & i).Value = .Range("A" & i).Value & "X"
            Checkpoint = .Range("A" & i).Address

            Else

            .Range("A" & i).Value = ""

            End If

            Else

            .Range("A" & i).Value = ""

            End If

            Next i

            End With

            End Sub





            share|improve this answer

























            • Thanks a lot for you code, i tried it and it worked, the problem is i want it to add one X each time i press the button

              – Sonofliberty11
              Mar 25 at 11:41











            • I have edited the answer. Could you please try again?

              – Error 1004
              Mar 25 at 12:32











            • I tried your eddited code, its better but it still put an X if he find a 0 in the offset cell, also i don't see the point of the checkpoint variable

              – Sonofliberty11
              Mar 25 at 15:06













            0












            0








            0







            Try the below (there are notes on the code). If you face difficulties let me know.



            Option Explicit

            Sub test()

            'In this example we assume that the data you want to loop appear in Column A

            Dim i As Long, Lastrow As Long
            Dim Checkpoint As Variant

            With ThisWorkbook.Worksheets("Sheet1") '<- Change sheet name if needed

            Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row '< -Fins the lastrow of the column you want to loop

            For i = 2 To Lastrow ' < -Start looping from row 2 to Lastrow fo the column

            If .Range("A" & i).Offset(0, 1).Value <> 0 Then '<- You are looping

            If .Range("A" & i).Value <> "X" Then

            .Range("A" & i).Offset(0, 1).Value = .Range("A" & i).Offset(0, 1).Value - 1

            .Range("A" & i).Value = .Range("A" & i).Value & "X"
            Checkpoint = .Range("A" & i).Address

            Else

            .Range("A" & i).Value = ""

            End If

            Else

            .Range("A" & i).Value = ""

            End If

            Next i

            End With

            End Sub





            share|improve this answer















            Try the below (there are notes on the code). If you face difficulties let me know.



            Option Explicit

            Sub test()

            'In this example we assume that the data you want to loop appear in Column A

            Dim i As Long, Lastrow As Long
            Dim Checkpoint As Variant

            With ThisWorkbook.Worksheets("Sheet1") '<- Change sheet name if needed

            Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row '< -Fins the lastrow of the column you want to loop

            For i = 2 To Lastrow ' < -Start looping from row 2 to Lastrow fo the column

            If .Range("A" & i).Offset(0, 1).Value <> 0 Then '<- You are looping

            If .Range("A" & i).Value <> "X" Then

            .Range("A" & i).Offset(0, 1).Value = .Range("A" & i).Offset(0, 1).Value - 1

            .Range("A" & i).Value = .Range("A" & i).Value & "X"
            Checkpoint = .Range("A" & i).Address

            Else

            .Range("A" & i).Value = ""

            End If

            Else

            .Range("A" & i).Value = ""

            End If

            Next i

            End With

            End Sub






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 25 at 12:32

























            answered Mar 25 at 10:54









            Error 1004Error 1004

            4,8132 gold badges6 silver badges25 bronze badges




            4,8132 gold badges6 silver badges25 bronze badges












            • Thanks a lot for you code, i tried it and it worked, the problem is i want it to add one X each time i press the button

              – Sonofliberty11
              Mar 25 at 11:41











            • I have edited the answer. Could you please try again?

              – Error 1004
              Mar 25 at 12:32











            • I tried your eddited code, its better but it still put an X if he find a 0 in the offset cell, also i don't see the point of the checkpoint variable

              – Sonofliberty11
              Mar 25 at 15:06

















            • Thanks a lot for you code, i tried it and it worked, the problem is i want it to add one X each time i press the button

              – Sonofliberty11
              Mar 25 at 11:41











            • I have edited the answer. Could you please try again?

              – Error 1004
              Mar 25 at 12:32











            • I tried your eddited code, its better but it still put an X if he find a 0 in the offset cell, also i don't see the point of the checkpoint variable

              – Sonofliberty11
              Mar 25 at 15:06
















            Thanks a lot for you code, i tried it and it worked, the problem is i want it to add one X each time i press the button

            – Sonofliberty11
            Mar 25 at 11:41





            Thanks a lot for you code, i tried it and it worked, the problem is i want it to add one X each time i press the button

            – Sonofliberty11
            Mar 25 at 11:41













            I have edited the answer. Could you please try again?

            – Error 1004
            Mar 25 at 12:32





            I have edited the answer. Could you please try again?

            – Error 1004
            Mar 25 at 12:32













            I tried your eddited code, its better but it still put an X if he find a 0 in the offset cell, also i don't see the point of the checkpoint variable

            – Sonofliberty11
            Mar 25 at 15:06





            I tried your eddited code, its better but it still put an X if he find a 0 in the offset cell, also i don't see the point of the checkpoint variable

            – Sonofliberty11
            Mar 25 at 15:06













            0














            Is plage a range?



            If so, you could update it to start from the checkpoint and include all cells up to some lastCell for example.



            Something like:



            set plage=thisWorkbook.Worksheets("Your Worksheet").Range(checkpoint,lastCell)


            That way the next For-Each should start from your checkpoint.



            BTW if I understand correctly what you'e trying to do, I would suggest you replace cell.value="" with cell.clearContents






            share|improve this answer



























              0














              Is plage a range?



              If so, you could update it to start from the checkpoint and include all cells up to some lastCell for example.



              Something like:



              set plage=thisWorkbook.Worksheets("Your Worksheet").Range(checkpoint,lastCell)


              That way the next For-Each should start from your checkpoint.



              BTW if I understand correctly what you'e trying to do, I would suggest you replace cell.value="" with cell.clearContents






              share|improve this answer

























                0












                0








                0







                Is plage a range?



                If so, you could update it to start from the checkpoint and include all cells up to some lastCell for example.



                Something like:



                set plage=thisWorkbook.Worksheets("Your Worksheet").Range(checkpoint,lastCell)


                That way the next For-Each should start from your checkpoint.



                BTW if I understand correctly what you'e trying to do, I would suggest you replace cell.value="" with cell.clearContents






                share|improve this answer













                Is plage a range?



                If so, you could update it to start from the checkpoint and include all cells up to some lastCell for example.



                Something like:



                set plage=thisWorkbook.Worksheets("Your Worksheet").Range(checkpoint,lastCell)


                That way the next For-Each should start from your checkpoint.



                BTW if I understand correctly what you'e trying to do, I would suggest you replace cell.value="" with cell.clearContents







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 25 at 10:41









                Stavros JonStavros Jon

                8373 silver badges11 bronze badges




                8373 silver badges11 bronze badges



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55335623%2fcreate-a-checkpoint-in-a-foreach-statement%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현