+ Reply to Thread
Results 1 to 9 of 9

How to select the next cell to the right in loop

  1. #1
    Registered User
    Join Date
    11-16-2015
    Location
    USA
    MS-Off Ver
    Window 7
    Posts
    28

    How to select the next cell to the right in loop

    I am trying to use a formula to select a date which is in cell "A1" and paste it in cell "K2". the take the value from "K2" add 7 days and put that value in "L2", then add +7 days to "L2" and put the value in "M2" and so on for the next 100 columns. is it possible to use Range(" ").select instead of cell(x,y) in offset formula?
    Any help is appreciated. Thank you!

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: How to select the next cell to the right in loop

    Hi Raja10,

    How about this:

    Please Login or Register  to view this content.
    If you don't want the formulas to remain just add ws.Range("L2").Resize(, 99).Value = ws.Range("L2").Resize(, 99).Value
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: How to select the next cell to the right in loop

    Without formulas...
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-16-2015
    Location
    USA
    MS-Off Ver
    Window 7
    Posts
    28

    Re: How to select the next cell to the right in loop

    It worked. Thank you!

    can you explain [ws.Range("L2").Resize(, 99).Formula = "=DATE(YEAR(K2),MONTH(K2),DAY(K2)+7)"]
    If possible can you also tell me how to use this in loop conditions?

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: How to select the next cell to the right in loop

    That line of code takes L2, resizes it 0 rows down and 99 across (for a total of 100)
    Then it applies a formula that takes the year of K2, month of K2, and day of K2 +7 days. However, when you set the formula like that, it works just like dragging across, and each cell to the right is taking the year date and day info from the cell to the left of it.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: How to select the next cell to the right in loop

    Oh and as far as the loop goes, I don't see why you'd want to loop 100 times instead of filling all cells in one shot, but you wouldn't use the formula approach then, you'd want dangelor's approach where vba just does the calculation. However like I posted, you can just add
    Please Login or Register  to view this content.
    to convert the formulas into static values, and that is in theory faster than a loop.

  7. #7
    Registered User
    Join Date
    11-16-2015
    Location
    USA
    MS-Off Ver
    Window 7
    Posts
    28

    Re: How to select the next cell to the right in loop

    this worked but the format is in number. how to change the format to (month/day) for example "may-27"?

  8. #8
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: How to select the next cell to the right in loop

    Try...
    Please Login or Register  to view this content.

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: How to select the next cell to the right in loop

    Please Login or Register  to view this content.

+ 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. [SOLVED] Loop through rows select the same cell
    By Scoobster_doo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-15-2017, 09:29 AM
  2. [SOLVED] How to select a certain cell in the loop
    By elmnas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-27-2015, 07:20 AM
  3. [SOLVED] Select Value in current cell while in a Loop
    By cooper.1651 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-01-2015, 09:58 PM
  4. [SOLVED] How to select the located cell after a loop for pasteing?
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-20-2014, 01:51 PM
  5. Loop and select
    By awan0126 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2011, 06:16 PM
  6. How can I loop this Select statement?
    By RynMan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-25-2009, 06:31 AM
  7. How to use Select Case in a loop
    By mikea3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2008, 02:09 AM

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