+ Reply to Thread
Results 1 to 7 of 7

VB only solving first row

  1. #1
    Registered User
    Join Date
    02-06-2014
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    4

    VB only solving first row

    I am new to all this and am looking for some help. I have a sheet with two columns of postcodes (column 1 and 3) and looking for each row to return the distance in column 5 and time in the 6. I have managed to get the code below working but it only returns the distance and time for the first row of the sheet. The code is below and if anyone can help I would be most greatful. I need it keep running down as far as there are rows with entries in column 1. Thank you in advance.

    Please Login or Register  to view this content.
    Last edited by phras81; 03-14-2014 at 12:30 PM.

  2. #2
    Forum Contributor
    Join Date
    11-13-2013
    Location
    United States
    MS-Off Ver
    2010
    Posts
    147

    Re: VB only solving first row

    Hi phras1,

    Welcome to the Forum.

    The first thing I noticed is the code is not setup to loop through the rows.

    Try this:

    Please Login or Register  to view this content.
    What I did was add a couple of variables .. the X variable counts up the rows as it loops through .. the Rng variable is a range where I started it at A1.

    What happens is it looks at the active cell in column 1 (column A) and if it is empty it will stop. If there is data there .. it goes through the code. the X variable represents the row number so when it is done, it moves to Row 2 and adds one to X making that a 2.

    Hope this helps.
    ----
    Mark threads as Solved
    Star those that help

  3. #3
    Registered User
    Join Date
    02-06-2014
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VB only solving first row

    Quote Originally Posted by ImStevenB View Post
    Hi phras1,

    Welcome to the Forum.

    The first thing I noticed is the code is not setup to loop through the rows.

    Try this:

    Please Login or Register  to view this content.
    What I did was add a couple of variables .. the X variable counts up the rows as it loops through .. the Rng variable is a range where I started it at A1.

    What happens is it looks at the active cell in column 1 (column A) and if it is empty it will stop. If there is data there .. it goes through the code. the X variable represents the row number so when it is done, it moves to Row 2 and adds one to X making that a 2.

    Hope this helps.
    Hi ImStevenB

    Sorry for the delay on response. Thank you for your help with this. I have tried the code but I am getting an error 1004. When I debug it takes me to the line Do While Rng.Offset(, -17).Value <> ""

    Can you help as I dont understand why it wouldnt work.

    Thank you again for your help.

  4. #4
    Forum Contributor
    Join Date
    11-13-2013
    Location
    United States
    MS-Off Ver
    2010
    Posts
    147

    Re: VB only solving first row

    Hi phras,

    I see the line .. just take the Offset out of the line. Instead of it saying:

    Please Login or Register  to view this content.
    Make it

    Please Login or Register  to view this content.
    It was trying to check a value 17 columns to the left .. and of course there is not one that is to the left of Column A.

    Hope this helps.

  5. #5
    Registered User
    Join Date
    02-06-2014
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VB only solving first row

    Thats great thank you. Can youo help with one other thing? It returns the number of miles in column 5 but it is followed by "mi" it means that I cannot sort the rows by closest to furthest away as 123 will come before 84 for example. Is there a way to just have it return the miles number with no text after?

    I think it is to do with
    Please Login or Register  to view this content.
    Thank you again for your help

  6. #6
    Forum Contributor
    Join Date
    11-13-2013
    Location
    United States
    MS-Off Ver
    2010
    Posts
    147

    Re: VB only solving first row

    Can you post a copy of your workbook? This way I can test it in your file.

  7. #7
    Registered User
    Join Date
    02-06-2014
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VB only solving first row

    Hi I have attached a copy of an example version. Thank you again for your help.
    Attached Files Attached Files

+ 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. Solving for PMT
    By Davidns in forum Excel General
    Replies: 0
    Last Post: 05-20-2011, 06:18 PM
  2. solving for combinations
    By stevenpaul in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2009, 04:23 AM
  3. Pls help me in solving
    By shanprimsw in forum Excel General
    Replies: 1
    Last Post: 05-18-2009, 02:37 AM
  4. Replies: 6
    Last Post: 12-09-2007, 11:09 AM
  5. Solving as x?
    By gpktm in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-14-2007, 12:42 AM

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