+ Reply to Thread
Results 1 to 6 of 6

Loop Problems

  1. #1
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Loop Problems

    Hi!

    I am very new to Macros and Vba in general so I need some help with a loop i need to do.

    I need to copy the range from "U10:X" & LastRow to "Q10:T" & LastRow in a loop until the last column in row 9.
    Good to know is that the LastRow will always be the same for every single loop.

    In other words I need to copy cell values and replace in four columns before and then delete the original numbers with a step on 8.

    My macro right now looks like this but it doesnt not work and is probably way off,

    Please Login or Register  to view this content.
    Would be great if someone could help me around.

    Sincerely,
    Niclas
    Last edited by vlady; 07-06-2015 at 03:14 AM. Reason: Use code tags around your codes. thank you.

  2. #2
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Loop Problems

    try this way:

    Please Login or Register  to view this content.
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Loop Problems

    Hi, the code can be changed aand made easier
    Please Login or Register  to view this content.
    I cannot figure out what you are doing exactly but the code above works, so maybe you could try it.
    Make sure you backup your sheet before you do
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  4. #4
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Loop Problems

    Thank you bulina, your macro worked I just needed to change one number since i copied to many columns. This is what I got now:

    Sub RefreshYear()

    Dim x As Long
    Dim y As Long
    Dim LastRow As Long
    Dim LastCol As Integer

    With ActiveSheet
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    LastCol = .Cells(9, .Columns.Count).End(xlToLeft).Column
    End With

    For x = 21 To LastCol Step 8
    y = LastRow
    Range(Cells(10, x), Cells(y, 3 + x)).Copy
    Range(Cells(10, x - 4), Cells(LastRow, x)).PasteSpecial xlPasteValues
    Next x
    End Sub

    The only thing I need to add now is that the data that was copied shall be deleted.

  5. #5
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Loop Problems

    data.png
    This is what the data look like. Data need to be copied from 2015 to 2014.

  6. #6
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Loop Problems

    you should first of all use code tags #
    then you should put this line just before the Next x statement:

    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. Problems with IF and DO WHILE LOOP
    By Ymgarl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2015, 03:02 PM
  2. Problems with a For Each loop
    By lordterrin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-27-2013, 02:10 PM
  3. Loop Problems
    By wesbuckley in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-06-2009, 06:38 AM
  4. problems with loop
    By Arjan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2005, 05:20 AM
  5. So close! Problems with Loop
    By Linking to specific cells in p in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2005, 02:06 PM

Tags for this Thread

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