Numus
12-25-2024, 04:16 AM
Hi all...new to VBA and forum.
I am working on a spreadsheet with a few VBA to help with calculations that cell formulas cannot complete.
Below is a portion of the VBA I have written (that is working) but as you can see it is calling specific cells and runs a loop which from what I have read is a poor way to code. Unfortunately, in this code, "X" is x = x +1 which is taking foooorrreeevvveeerrr to complete because it can actually end up in the 100,000.00 + range when complete.
Sub step5()
Dim x As Long
x = CLng(1)
If ActiveWorkbook.Worksheets("Pre Trial").Range("G22").Value <= 0.5 Then
Exit Sub
Else
Do Until ActiveWorkbook.Worksheets("Pre Trial").Range("R38").Value <= Range("R37").Value _
Or Range("R38").Value = 0.5 Or Range("G32").Value = Range("R32").Value
Range("G32").Value = x
x = x + 1
ActiveWorkbook.Worksheets("Pre Trial").Range("G35").Value <= Range("R34").Value
Loop
End If
ActiveWorkbook.Worksheets("Pre Trial").Range("G35").Value <= Range("R34").Value
End Sub
Any ideas or help would be greatly appreciated.
Thanks all!!
I am working on a spreadsheet with a few VBA to help with calculations that cell formulas cannot complete.
Below is a portion of the VBA I have written (that is working) but as you can see it is calling specific cells and runs a loop which from what I have read is a poor way to code. Unfortunately, in this code, "X" is x = x +1 which is taking foooorrreeevvveeerrr to complete because it can actually end up in the 100,000.00 + range when complete.
Sub step5()
Dim x As Long
x = CLng(1)
If ActiveWorkbook.Worksheets("Pre Trial").Range("G22").Value <= 0.5 Then
Exit Sub
Else
Do Until ActiveWorkbook.Worksheets("Pre Trial").Range("R38").Value <= Range("R37").Value _
Or Range("R38").Value = 0.5 Or Range("G32").Value = Range("R32").Value
Range("G32").Value = x
x = x + 1
ActiveWorkbook.Worksheets("Pre Trial").Range("G35").Value <= Range("R34").Value
Loop
End If
ActiveWorkbook.Worksheets("Pre Trial").Range("G35").Value <= Range("R34").Value
End Sub
Any ideas or help would be greatly appreciated.
Thanks all!!