0

I am currently doing a project on VBA. When implementing loop I encountered problems as my formulas do not work. If anyone could help me I would really appreciate it. It was supposed to count number of days from order till shipment date and then creating a loop to show as many results as the filter does. The macro will be assigned to a new button so basically it will not have any connections with filtering. I believe that the issue lays in loop.

Sub DateDiff_Day()
Range("O8").Select
Do Until ActiveCell.Value = " "
Dim datValue1 As Date
Dim datValue2 As Date
datValue1 = Worksheets("Adv.filter, Pivot, Chart").Range("F8")
datValue2 = Worksheets("Adv.filter, Pivot, Chart").Range("H8")
CopyToRAnge: Worksheets("Adv.filter, Pivot, Chart").Range("O8") = DateDiff("d", datValue1, datValue2)
 Loop
End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
  • The loop is infinite, you are never selecting a different cell. You may want to avoid using select in your macros. Please edit your question and post some sample data. – Ricardo Diaz Jan 29 '20 at 23:59
  • 1
    `Do Until ActiveCell.Value = " "` Avoid looping through cells like this. Find the last row as shown [HERE](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba/11169920#11169920) and then use a **For Loop**. for example `For i = 1 to LastRow` – Siddharth Rout Jan 30 '20 at 04:47

0 Answers0