Results 1 to 6 of 6

Looping through columns

Threaded View

  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    melbourne australia
    MS-Off Ver
    office 365
    Posts
    41

    Looping through columns

    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
    Last edited by AliGW; 04-15-2019 at 07:14 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Looping thru columns for value
    By Quint6778 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2017, 04:59 PM
  2. [SOLVED] Looping through .Columns
    By efarkouh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-21-2017, 02:01 PM
  3. [SOLVED] Looping through columns
    By Peterhmg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-09-2016, 08:34 AM
  4. Looping through columns
    By figuraluk in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-20-2013, 01:06 PM
  5. Looping through two columns
    By pablowilks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2013, 02:46 AM
  6. Do Until Looping (not looping through all other columns)
    By orle8050 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2013, 10:37 AM
  7. Looping over columns
    By LATrojan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-27-2010, 08:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1