VBA Do While Loop does not want to looping

0 votes

I need to divide each integer in a table by the last one in each column, iterating through each column only when the condition is satisfied. After that, it ought to exit the loop and move to the first one. I argue that this loop should iterate over a new line each time (the line below). Unfortunately, I am unable to make this work. It moves on to the second loop, fills every cell in a subsequent sheet, and then ends. There is no more row in the program.

ee my code, please let me know what I do wrong.

currentCol = 4
currentRow = 11


Do While originalSheet.Cells(currentRow, 1).Value <> ""


     Do While currentHeader <> "Finish" 
        
        currentHeader = originalSheet.Cells(8, currentCol).Value
    
        divider1 = originalSheet.Cells(currentRow, currentCol).Value
        divider2 = originalSheet.Cells(17, currentCol).Value
    
        If divider1 <> 0 Then
            divisionResult = divider1 / divider2
        Else
            divisionResult = 0
        End If
    
        newSheet.Cells(currentRow, currentCol).Value = divisionResult
    
       
        currentCol = currentCol + 2
   
     Loop
        
 currentRow = currentRow + 1   
        
    
Loop
Feb 27, 2023 in Others by Kithuzzz
• 38,020 points
580 views

1 answer to this question.

0 votes

Try this:

currentRow = 11

Do While originalSheet.Cells(currentRow, 1).Value <> ""

    currentCol = 4
    
    Do While originalSheet.Cells(8, currentCol).Value <> "Finish"
        
        divider1 = originalSheet.Cells(currentRow, currentCol).Value
        divider2 = originalSheet.Cells(17, currentCol).Value
    
        If divider2 <> 0 Then
            divisionResult = divider1 / divider2
        Else
            divisionResult = 0
        End If
    
        newSheet.Cells(currentRow, currentCol).Value = divisionResult
    
        currentCol = currentCol + 2
   
    Loop
    
    currentRow = currentRow + 1
        
Loop
answered Mar 18, 2023 by narikkadan
• 63,720 points

Related Questions In Others

0 votes
1 answer

How to increment the Range of a For Each loop - Excel VBA

Your formula seems to sum 1 single ...READ MORE

answered Jan 7, 2023 in Others by narikkadan
• 63,720 points
2,607 views
0 votes
1 answer

VBA Loop To Import Changing File Names

You can use a FOR loop and ...READ MORE

answered Jan 12, 2023 in Others by narikkadan
• 63,720 points
796 views
0 votes
1 answer

I want to compare two Excel files and highlight the differences with VBA

The workbook doesn't have the UsedRange property ...READ MORE

answered Jan 13, 2023 in Others by narikkadan
• 63,720 points
2,462 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,079 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,495 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
803 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
976 views
0 votes
1 answer
0 votes
1 answer

I have filtered my Excel data and now I want to number the rows. How do I do that?

Solution Filter your data. Select the cells you want ...READ MORE

answered Nov 14, 2022 in Others by narikkadan
• 63,720 points
1,062 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP