+ Reply to Thread
Results 1 to 10 of 10

Loop through columns then next row with unit convert

  1. #1
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Loop through columns then next row with unit convert

    All of my attempts to simplify this lop have failed an every change I have to make to the if statement has to be made over and over for all lines. Starting at the second row it is supposed to check to make sure the cell in column 5 of the current row is greater than zero to start reading through the rows. Then to check the value in the top cell of the current column and if its value matches one of the two values listed in the if then statements. Values range from -2.11 to 2.1. If the statement is satisfied then the corresponding value of the row and column would be converted from meters to inches and written to the new sheet "Upchain Edit" in the column with the corresponding column header value instead of equaling line = line +BLAHBLAH.

    Example new sheet header layout:
    Excel.JPG

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by cnash52; 03-03-2016 at 11:34 AM. Reason: Added example csv to be edited

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Loop through columns then next row with unit convert

    seems that you have very systematic change - why not use another loop?

    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Loop through columns then next row with unit convert

    I tried something like this but when there is a value in the Header and Header-0.1 then it would get messed up.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Loop through columns then next row with unit convert

    When there is a value in both of the if statement headers then the statement is satisfied twice for one row and ends up offsetting incorrectly in the new file.

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Loop through columns then next row with unit convert

    there is huge difference between
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    can you see it?
    if not, try in immediate window:
    Please Login or Register  to view this content.
    Last edited by Kaper; 03-03-2016 at 11:38 AM.

  6. #6
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Loop through columns then next row with unit convert

    As I run he below code I get several empty cells and zero cells

    Please Login or Register  to view this content.
    Here is an example of what the newly created "Upchain Edit" looks like
    Excel.JPG

    Looking at the csv in the first post U4 would be the first non-zero value that falls within the if statements and should be placed in cell C2 of the new sheet and the first one works.
    Excel.JPG

    Then it goes right back to blank for D2 when there should be a value corresponding to AF4 if converted from meters to inches.
    Excel.JPG
    Attached Images Attached Images
    Last edited by cnash52; 03-03-2016 at 12:54 PM.

  7. #7
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Loop through columns then next row with unit convert

    If anyone could help me with figuring out why the loop is leaving so many blanks it would be greatly appreciated. Kaper helped some but the loop still isn't working correctly and he has messaged me to let me know that he isn't going to "waste his time" assisting further and is quitting this thread. Thank you very much in advance.

  8. #8
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Loop through columns then next row with unit convert

    Indeed.
    The code snippets are far from complete.
    Such variables as CurSta, StartStation, Direction, etc are probably meaningfull, but only for Author, and not for those who try to help.
    Data format in csv is different than screenshots.
    ...
    So please join us.
    t could be just mine deficiency with interpreting what is available and helping.
    And someone with fresh view could help in no time.

  9. #9
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Loop through columns then next row with unit convert

    Those three variables have no effect on this loop and are from a prior loop. I plan to add them back in but I have to get this loop to call the values correctly first. I don't know if this will help but I have been fighting with this all day yesterday.

    I have attached a macro enabled version of the worksheet. The button on the first sheet will open the form. The first button "Get Upchain File" will direct you to a browse window to select the reference file (the attached csv). You can use the same file for upchain and downchain because downchain is not set up yet. Nothing needs to be entered in pin or start station. When you click "Process Data" the macro involving the issue loop will run. It is supposed to reference the data in the "Upchain" sheet and run through the loop slimming down the data and writing to the "Upchain Edit" sheet based on the if statements. I believe there is something wrong with the if statement because when A=4, B=32, C=3, and i=2 there is a value in the "Upchain" sheet that should satisfy the if statement but it skips to the next C as if it doesn't satisfy the statement. This is the first instance of incorrect read/write.

    If there are any questions please feel free to ask.

    The MsgBox if statement on line 103 was just for trying to locate the issue and can be deleted.
    Attached Files Attached Files
    Last edited by cnash52; 03-04-2016 at 08:34 AM.

  10. #10
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Loop through columns then next row with unit convert

    The error was in the convert function all along. Remove the function or have it go from"m" to "m" and it populates correctly.

+ 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. Replies: 4
    Last Post: 10-07-2015, 06:04 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. [SOLVED] Unit increase relative to variable unit thresholds
    By Fr3dle in forum Excel General
    Replies: 6
    Last Post: 07-01-2013, 06:57 AM
  5. Replies: 4
    Last Post: 06-07-2013, 02:01 PM
  6. [SOLVED] Use VBA to run "text to columns' Loop on first row to convert from text to date format
    By csmiley in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-03-2013, 02:06 PM
  7. convert unit change to percentile rank change
    By dujang in forum Excel General
    Replies: 1
    Last Post: 11-15-2006, 02:53 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