+ Reply to Thread
Results 1 to 10 of 10

loop to go across columns

  1. #1
    Forum Contributor
    Join Date
    06-17-2013
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    247

    loop to go across columns

    Hi!

    So i need help, i have this script which i use to list out datebands however my start date and end date have multiple ranges so i have a list of dates in the first row and i want to add all the dates to the left hand side.

    E.G
    a1 = sdate
    b1 = edate
    c1 = sdate
    d1 = edate and so on and so forth until there are no more dates in the first row.

    How can i change my script so that it automatically does a1:b1 as sdate edate, list the dates between the ranges then move onto c1 as sdate and d1 as edate and put the dates inbetween that range underneth the rest of the dates and so on until there is no date is the first row.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: loop to go across columns

    Try running this:

    Please Login or Register  to view this content.
    多么想要告诉你 我好喜欢你

  3. #3
    Forum Contributor
    Join Date
    06-17-2013
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    247

    Re: loop to go across columns

    Hi Millz!

    That worked for the first date range, cells A1 & b1 however came up with a Type Mismatch after that on this line : For j = Cells(1, i).Value To Cells(1, i + 1).Value

  4. #4
    Forum Contributor
    Join Date
    06-17-2013
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    247

    Re: loop to go across columns

    Oopps, nevermind that didnt work as the dates had spaces in them, i removed the spaces that worked okay!!!! However is there anyway to make all of the dates go under each other in column A rather than spread out under each start date?

    Thank you!!!!!

  5. #5
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: loop to go across columns

    What about this?

    Please Login or Register  to view this content.
    Edit: Just saw your last post. Amended.

  6. #6
    Forum Contributor
    Join Date
    06-17-2013
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    247

    Re: loop to go across columns

    thanks for your quick reply millz, unfortunately that didnt return the correct values like the first one,
    everything is for the year 2016

  7. #7
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: loop to go across columns

    Sorry I did a test myself and found there's actually a problem for removing sc = 4, it should be placed outside the loop instead. I guess just stick to the one without CLng. Here's the amended code.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    06-17-2013
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    247

    Re: loop to go across columns

    you sir, are an absolute legend!

    Thank you so much for your help, i really need to practice my looping..

    thank you!!!!!!!!!!

  9. #9
    Forum Contributor
    Join Date
    06-17-2013
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    247

    Re: loop to go across columns

    Just so i understand this correctly, can you let me know if this is broken down correctly?

    sc = 4 'this is the start row?
    For i = 1 To Columns.Count Step 2 'i = 1 means that it starts at column 1, if it was 2 it would start at column B etc..

    basically i want to know how to change the script so that i can point it to dates in the correct row/ start column.

    E.g E2 is the first start date.. Just so i can understand it correctly

  10. #10
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: loop to go across columns

    Quote Originally Posted by 13lack13lade View Post
    sc = 4 'this is the start row?
    For i = 1 To Columns.Count Step 2 'i = 1 means that it starts at column 1, if it was 2 it would start at column B etc..
    Yes and yes.

    sc was also based on what you have, sc = A4, so row 4.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Loop through several columns
    By amphinomos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2014, 09:47 AM
  2. Loop Across Columns...If Blank Cell, Loop Down Rows
    By flindy87 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2014, 07:05 PM
  3. Loop Across Columns If Blank Cell Loop Down Rows
    By flindy87 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2014, 10:22 AM
  4. How to loop through columns
    By todd18us in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-31-2013, 01:50 AM
  5. loop through columns in range and only copy columns that have value of 0
    By gherzberg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-07-2012, 12:55 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