Consulting

Results 1 to 6 of 6

Thread: Excel Code Help, Loop related

  1. #1

    Excel Code Help, Loop related

    Hi guys

    So... I've got 3 columns in my excel spreadsheet, I,J and L. Looks something like this:


    I J L
    1 1 1
    3 3 3
    4 7 4
    5
    6
    7

    The column L is supposedly empty but I wanna make those numbers appear there.L would be based on I and J. The below is my code. Some help would be much appreciated .

    Sub trial2()


    Dim cell As Range
    Dim i As Integer
    Dim j As Integer
    Dim c As Range




    i = 0
    j = 0


    For Each c In Columns("L")
    i = i + 1
    j = j + 1
    c = i

    If Cells(i, "I").Value = Cells(i, "J").Value Then
    Cells(j, "L").Value = Cells(i, "J").Value
    ElseIf Cells(i, "I").Value < Cells(i, "J").Value Then
    Cells(j, "L").Value = Cells(i, "I").Value + 1



    End If


    Next c


    End Sub

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    L1 Formula = "=If(I1=J1,J1,If(I1<J1,I1+1,0))"
    Copy down
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    hi thanks for your reply but i kinda need a different outcome.

    something like this:

    i j L
    940897 940897 940897
    940902 940921 940902
    940921 940921 940903

    940904

    940905

    940906

    until 940921



    the heading for i and j are sorta like sample start and sample end. while L heading is like total samples. Hope that helps you understand. Sorry for the inconvenience.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,844
    If you must cross-post then you are supposed to supply links to those cross posts.
    https://www.mrexcel.com/forum/excel-...p-related.html
    Anywhere else? (MrExcel has the same requirement)

    I suggest you attach a small workbook where:
    On Sheet 1 you have your original arrangement of data
    On Sheet 2 you have what you want the result to be.

    Computers aren't very good with the likes of 'sorta' and 'kinda'.
    Last edited by p45cal; 01-16-2018 at 05:12 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    i kinda need a different outcome.
    That's an entirely different situation than what's in your first post.

    Are you sure that's what you want? I would hate to have you change your mind again after somebody put in a lot of time and effort on providing that.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    Quote Originally Posted by SamT View Post
    That's an entirely different situation than what's in your first post.

    Are you sure that's what you want? I would hate to have you change your mind again after somebody put in a lot of time and effort on providing that.
    All G Sam I managed to figure it out. Thanks everyone for helping

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •