Hi all
So got some code where i essentially do the same thing to each column between columns between cells G5 and P5
Just wondering if theres a way i can rewrite this into a loop. I know how to loop through rows pretty easily, gust replace "C1" with "C"&x and have x=x+1 at the end of each loop. but am confused how to do it with columns. any advice would be greatly appreciated
tbh dont really "need" it as the code will work fine as is, but it is more so i learn how to do it properly (as well as more cleanly and so i know how its done in the future if i ever need to accomplish something similar)
code below
![]()
Sheets("temp").Range("G5").Value = rando1 rando1 = Int((Worksheets("vars").Range("C1").Value - Worksheets("vars").Range("B1").Value + 1) * Rnd + Worksheets("vars").Range("B1").Value) Sheets("temp").Range("H5").Value = rando1 rando1 = Int((Worksheets("vars").Range("C1").Value - Worksheets("vars").Range("B1").Value + 1) * Rnd + Worksheets("vars").Range("B1").Value) Sheets("temp").Range("I5").Value = rando1 rando1 = Int((Worksheets("vars").Range("C1").Value - Worksheets("vars").Range("B1").Value + 1) * Rnd + Worksheets("vars").Range("B1").Value) Sheets("temp").Range("J5").Value = rando1 rando1 = Int((Worksheets("vars").Range("C1").Value - Worksheets("vars").Range("B1").Value + 1) * Rnd + Worksheets("vars").Range("B1").Value) Sheets("temp").Range("K5").Value = rando1 rando1 = Int((Worksheets("vars").Range("C1").Value - Worksheets("vars").Range("B1").Value + 1) * Rnd + Worksheets("vars").Range("B1").Value) Sheets("temp").Range("L5").Value = rando1 rando1 = Int((Worksheets("vars").Range("C1").Value - Worksheets("vars").Range("B1").Value + 1) * Rnd + Worksheets("vars").Range("B1").Value) Sheets("temp").Range("M5").Value = rando1 rando1 = Int((Worksheets("vars").Range("C1").Value - Worksheets("vars").Range("B1").Value + 1) * Rnd + Worksheets("vars").Range("B1").Value) Sheets("temp").Range("N5").Value = rando1 rando1 = Int((Worksheets("vars").Range("C1").Value - Worksheets("vars").Range("B1").Value + 1) * Rnd + Worksheets("vars").Range("B1").Value) Sheets("temp").Range("O5").Value = rando1 rando1 = Int((Worksheets("vars").Range("C1").Value - Worksheets("vars").Range("B1").Value + 1) * Rnd + Worksheets("vars").Range("B1").Value) Sheets("temp").Range("P5").Value = rando1
Bookmarks