+ Reply to Thread
Results 1 to 18 of 18

trying to use vlookup?

Hybrid View

  1. #1
    Registered User
    Join Date
    07-10-2012
    Location
    uk
    MS-Off Ver
    Excel 2007
    Posts
    10

    trying to use vlookup?

    hi,

    i have a one column of about 500,000 numbers - either 0 or 1.
    i need to know: each time the column reads 1, how many rows until it reads a 0; and then how long until the next 1.

    ideally this will leave me with a shorter dataset something like:

    1 5
    0 2
    1 3
    0 1
    1 8
    0 2
    1 7
    0 11

    obviously the first column would be easy to generate if i can generate the second...

    thanks for any answers !
    Last edited by clemmon; 07-10-2012 at 06:26 PM. Reason: sorry - very confusing typo!!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: trying to use vlookup?

    Hi,

    Your request is not clear. Explain how you arrive at the numbers in column B with reference to the column A cell refs.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-10-2012
    Location
    uk
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: trying to use vlookup?

    oh sorry - column B is the length until the next time the value in column A appears. column A just cycles between 0 and 1.

    not actually sure that's the most efficient way of having the data, but yeah. thanks!
    Last edited by clemmon; 07-10-2012 at 06:42 PM. Reason: not sure i'm expressing myself well

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: trying to use vlookup?

    @clemmon

    Hi,
    That's just a repeat of what you said originally. What I'm trying to understand is why you have the value 5 against the first value 1 in column A when the next 1 down column A is 2 rows below.

    Ditto the 3 in B3. A3 is zero and the next 1 is in A5, 2 rows below not 3

    Please explain.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: trying to use vlookup?

    It's a frequency table representing the original column of just 1's and 0's.

    If the original data is to be overwritten then only this code:

    Cells(r, i + 1) = H: Cells(r, i + 2) = k: k = 0: r = r + 1
    needs to be altered:

    Cells(r, i ) = H: Cells(r, i + 1) = k: k = 0: r = r + 1
    It's now set up to place the items and their frequencies beside the original data, of course that leaves the problem of what to do with the original data - one option is to delete those lines once they're counted.

    The assignments:

    ASSIGNATIONS:
    i = 7: j = 4: r = j: k = 0: S = Cells(j, i): H = S
    Are set up to start in G4 from whence I did my testing.

    ASSIGNATIONS:
    i = 1: j = 1: r = j: k = 0: S = Cells(j, i): H = S
    By just changing the i - Column and j - row to ones the routine would key on A1.
    Last edited by xladept; 07-11-2012 at 01:58 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  6. #6
    Registered User
    Join Date
    07-10-2012
    Location
    uk
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: trying to use vlookup?

    Quote Originally Posted by Richard Buttrey View Post
    @clemmon

    Hi,
    That's just a repeat of what you said originally. What I'm trying to understand is why you have the value 5 against the first value 1 in column A when the next 1 down column A is 2 rows below.

    Ditto the 3 in B3. A3 is zero and the next 1 is in A5, 2 rows below not 3

    Please explain.
    the 5 means that there are 5 1s in a row in the original data, then there are 2 zeros, then there are 3 1s next to each other...

    make sense now ? sorry!

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: trying to use vlookup?

    Hi clemmon,

    If you want to overwrite the original data then only increment the second column index.

    Sub OnOff(): Dim S As String, H As String
    Dim r As Long, i As Long, j As Long, k As Long
    
    ASSIGNATIONS:
    i = 7: j = 4: r = j: k = 0: S = Cells(j, i): H = S
    
    Do Until S = ""
    S = Cells(j, i)
    If S = H Then
    k = k + 1
    Else
    Cells(r, i + 1) = H: Cells(r, i + 2) = k: k = 0: r = r + 1
    End If
    H = S: j = j + 1: Loop
    End Sub
    (I ran my test from G4)

  8. #8
    Registered User
    Join Date
    07-10-2012
    Location
    uk
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: trying to use vlookup?

    hi,

    unfortunately i have no idea how to use code. i will try to get google to fill in the blanks for me - unless that is there's an easier way?


    thanks

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: trying to use vlookup?

    Here are some instructions I copied from one of the major contributors:

    First Save Your Book As Macro Enabled - extension .xlsm

    Copy the code I posted
    With your file open, press Alt+F11 to display the VBA editor
    Go to the Insert menu and select Module
    Paste the code I provided

    After pasting - modify the assignations to conform to your own book.

    Then you can play the macro several ways - if you have the worksheet opened before you
    and you're looking at the code then place the cursor within the code and hit F5
    or GoTo Tools-Macro-Macros-"OnOff"

  10. #10
    Registered User
    Join Date
    07-10-2012
    Location
    uk
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: trying to use vlookup?

    ok thanks xladept!

    last question would just be that it's not immediately obvious what bits of the code i should modify. i can probably use some common sense though...

    thanks again

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: trying to use vlookup?

    Modify the assignations for sure because that's where the whole routine is specifically defined.

  12. #12
    Registered User
    Join Date
    07-10-2012
    Location
    uk
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: trying to use vlookup?

    ok, i'll try that now, thanks...

    however, there's another operation i may want to run first?
    each time the original data-set cycles from 0 to 1, i want to repeat the data.

    so e.g., if the data original read 0 1 0 1 0 0 1 1
    i would want it to read -> 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1.


    make sense? is there a simple way of achieving this?



    thanks

  13. #13
    Registered User
    Join Date
    07-10-2012
    Location
    uk
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: trying to use vlookup?

    kinda drowning in excel atm (not done maths in 10 years)... but how can i reverse the process?

    so e.g. if i have 1 3 6 4
    that is 0 1 1 1 0 0 0 0 0 0 1 1 1 1

    any help?? i don't even know if that's what i want yet


    cheers!!!

  14. #14
    Registered User
    Join Date
    07-10-2012
    Location
    uk
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: trying to use vlookup?

    btw that code worked great. but idk how to reverse it and that's maybe what i want now.
    probably the last thing i need from excel atm.


    thanks so much for any further advice

  15. #15
    Registered User
    Join Date
    07-10-2012
    Location
    uk
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: trying to use vlookup?

    hi, i can't start new threads - i just get a blank screen when i do. so i can't start one asking about this second problem

    so i'll bump this instead ??

  16. #16
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: trying to use vlookup?

    I don't get it - I'll study it anon.

  17. #17
    Registered User
    Join Date
    07-10-2012
    Location
    uk
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: trying to use vlookup?

    well it's ok - i'm using max/msp to sort the data. thanks !

  18. #18
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: trying to use vlookup?

    OK then - Good Luck!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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