Macro For-next Loop Problem Excel

%3CLINGO-SUB%20id%3D%22lingo-sub-2895376%22%20slang%3D%22en-US%22%3EMacro%20For-next%20Loop%20Problem%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2895376%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22product_resoul.PNG%22%20style%3D%22width%3A%20646px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F320797i981B27C7F2F687FB%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22product_resoul.PNG%22%20alt%3D%22product_resoul.PNG%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22resoult_excel.PNG%22%20style%3D%22width%3A%20646px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F320796i6BE796EDAAE0C9E5%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22resoult_excel.PNG%22%20alt%3D%22resoult_excel.PNG%22%20%2F%3E%3C%2FSPAN%3EHello%2C%3CBR%20%2F%3EI%20need%20to%20pull%20two-column%20data%20from%20one%20sheet%20to%20another%20sheet%20in%20Excel%20according%20to%20certain%20rules%2C%3CBR%20%2F%3EI%20have%20three%20different%20main%20determinants.%3CBR%20%2F%3EI%20wrote%20a%20code%20specific%20to%20the%20first%20case%20below%2C%20The%20same%20code%20works%20fine%20on%20the%20previous%20month's%20data%2C%20but%20when%20trying%20to%20pull%20this%20month's%20data%2C%20it%20causes%20a%20problem.%3CBR%20%2F%3EWhen%20I%20run%20the%20following%20code%2C%20the%20data%20appears%20and%20disappears%20very%20quickly.%3C%2FP%3E%3CP%3EHow%20can%20I%20solve%20it%3F%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESub%20nergis_gunluk_hesaplama_kanal_bazli()%0A%20%20%20%20last%20%3D%20Worksheets(%22Genel_Ortalama%22).Range(%22B%22%20%26amp%3B%20Rows.Count).End(xlUp).Row%0A%20%20%20%20For%20j%20%3D%204%20To%20last%0A%20%20%20%20%20%20%20%20If%20ThisWorkbook.Sheets(%22Genel_Ortalama%22).Cells(j%2C%203).Value%20%3D%20%22nergis%22%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20'For%20m%20%3D%204%20To%2033%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ThisWorkbook.Sheets(%22Genel_Ortalama%22).Cells(j%2C%205).Value%20%3D%20ThisWorkbook.Sheets(%22EKIM_ORT%22).Cells(m%2C%202).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ThisWorkbook.Sheets(%22Genel_Ortalama%22).Cells(j%2C%206).Value%20%3D%20ThisWorkbook.Sheets(%22EKIM_ORT%22).Cells(m%2C%206).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20m%20%3D%20m%20%2B%201%0A%20%20%20%20%20%20%20%20%20%20%20%20'Next%20j%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20j%20%3D%20j%20%2B%202%0A%20%20%20%20Next%20j%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2895376%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20for%20web%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20Scripts%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

product_resoul.PNGresoult_excel.PNGHello,
I need to pull two-column data from one sheet to another sheet in Excel according to certain rules,
I have three different main determinants.
I wrote a code specific to the first case below, The same code works fine on the previous month's data, but when trying to pull this month's data, it causes a problem.
When I run the following code, the data appears and disappears very quickly.

How can I solve it?

Sub nergis_gunluk_hesaplama_kanal_bazli()
    last = Worksheets("Genel_Ortalama").Range("B" & Rows.Count).End(xlUp).Row
    For j = 4 To last
        If ThisWorkbook.Sheets("Genel_Ortalama").Cells(j, 3).Value = "nergis" Then
            'For m = 4 To 33
                ThisWorkbook.Sheets("Genel_Ortalama").Cells(j, 5).Value = ThisWorkbook.Sheets("EKIM_ORT").Cells(m, 2).Value
                ThisWorkbook.Sheets("Genel_Ortalama").Cells(j, 6).Value = ThisWorkbook.Sheets("EKIM_ORT").Cells(m, 6).Value
            m = m + 1
            'Next j
        End If
    j = j + 2
    Next j
End Sub

 

1 Reply
I don't have an answer to your question, but I do want to share this: It is bad practice to change the value of a loop counter within the loop. I think your loop will do the same if you change
For j = 4 To last
to:
For j = 4 To last Step 3
and delete the line j = j + 2.