+ Reply to Thread
Results 1 to 5 of 5

Macro Only Works For One Column

  1. #1
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Macro Only Works For One Column

    Hello,

    The macro below will only output in column G.

    When I change the output column it will not propagate the column. i.e. F ,G, H,I etc

    Also , when I change the input column to another letter besides D it will not work. The input column has values in it and I copy and pasted the values to other columns trying different input columns.

    Your help will be greatly appreciated.

    Please Login or Register  to view this content.
    Last edited by rmccain; 12-08-2017 at 03:16 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,996

    Re: Macro Only Works For One Column

    I don't have any problem with the code except that you are recalculating x within the loop at several places without checking if it is <= 2 which can cause the row pointer to become < 1.
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: Macro Only Works For One Column

    Hello,

    Thankyou very much for your time and your response.

    I am trying to figure this out, doesn't the code below already do this ?

    If not what am I missing; I am baffled.

    Please Login or Register  to view this content.

    Thankyou again

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,996

    Re: Macro Only Works For One Column

    No. You are starting off by finding the last used row in column D.
    The line: llastrow = Range("I" & Rows.Count).End(xlUp).Row is only run once.

    You have a loop controlled by x which starts off at llastrow; However, inside the loop, you have:

    x = x - c - 2
    and
    x = x - c
    one of which will decrement x inside the loop depending on the outcome of the IF..Then test. Notice that c is incremented inside Do..Loops and it may be possible that c will become larger than x. (Can't be sure without a sample workbook).

    Finally,
    Next x will always decrement x by another 1 since you are stepping by -1. So that it is possible to have a zero or negative row value which will fail the code.

    * I tested with Rnd() in column D and it did crash several times, but it did write to any other specified column.
    Last edited by protonLeah; 12-09-2017 at 04:06 PM.

  5. #5
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: Macro Only Works For One Column

    Oooh Ok,

    Thankyou for your help.

+ 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] macro works but when added to button macro, it fails, dont know why
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-06-2016, 01:20 PM
  2. Problem with recording a macro with long formula - works in Excel but not in macro
    By tonybeo2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-28-2015, 11:25 AM
  3. Replies: 2
    Last Post: 11-02-2014, 01:31 AM
  4. [SOLVED] VBA Macro for Range().End(xlUp).Row works for middle of column but oddly, not top/bottom
    By justinbelkin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-17-2013, 03:13 PM
  5. Replies: 5
    Last Post: 05-04-2013, 01:42 PM
  6. [SOLVED] how to set a macro that only works when the active cell is on a certain column?
    By kjy1989 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2013, 02:06 AM
  7. [SOLVED] Macro error when ran on multiple sheets on workbook (even though macro works)
    By steven_e in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2012, 06:09 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