+ Reply to Thread
Results 1 to 9 of 9

How to set variable in "for each cell in range" procedure

  1. #1
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    How to set variable in "for each cell in range" procedure

    Hi. My question is somehow related to another question I posted earlier today (see link). By the way, how do I add a link without this huge string? I've tried the icon above but it doesn't seem to work.

    So here is the link: "http://www.excelforum.com/excel-formulas-and-functions/953870-how-to-identifying-specific-strings-in-a-column.html?p=3400160#post3400160"

    The difference this time I need VBA code, for better flexibility:
    Please Login or Register  to view this content.
    I need matching pairs in column A like hai_a and a_hai (matching: if they have the same string in the opposite sides of =) to be written down in column B. As the file attached shows. But my code is not too good since I'll need to replace each time for examle "hai" with "bvr" (shown in the file) and so on. I'm trying to use a variable instead, inside the loop, so it'll look for - using my code - pairs..
    Attached Files Attached Files
    Last edited by GIS2013; 09-10-2013 at 01:06 PM. Reason: Typo

  2. #2
    Registered User
    Join Date
    12-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: How to set variable in "for each cell in range" procedure

    Not sure what you're trying to accomplish.

    Could you please fill out column B in your attachment with the values you want returned?

    Example:
    Col A-----Col B
    a_hai-----a_hai
    hai_a-----hai_a
    bvr_x-----?


    Are you comparing A2 & A3 (every 2 rows)?

  3. #3
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to set variable in "for each cell in range" procedure

    Sure, please see desired pairs in column C. I'd should add that the list is longer than you see in the sample, so it's rather tedious task to match all these pairs.
    Attached Files Attached Files
    Last edited by GIS2013; 09-10-2013 at 02:17 PM.

  4. #4
    Registered User
    Join Date
    12-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: How to set variable in "for each cell in range" procedure

    I don't understand what you're trying to accomplish.

    I see that you start off with nc_sc, which does not have the reversed value in the adjacent row. tx_az & az_tx specifically don't relate to either row 10 or 11, so how did you determine where to place these values? Shouldn't it appear in C6 & C7?

  5. #5
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to set variable in "for each cell in range" procedure

    hi larai. Look at column A (titled "current"). you can see nc_sc, right? well I need a macro which would look for the "opposite" of nc_sc in column A which is sc_nc, right? and then after a matching has been found, both nc_sc and its opposite sc_nc will be placed one above the other in column c (titled "goal"). hope it's more clear now. I'll check replies (if any) later. thanks!

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,784

    Re: How to set variable in "for each cell in range" procedure

    Quote Originally Posted by GIS2013 View Post
    By the way, how do I add a link without this huge string? I've tried the icon above but it doesn't seem to work..
    What icon did you try?

    There are two ways to include a link. One is to simply put the full URL in your post. If you scroll down while editing your post, you will see a checkbox marked "Automatically parse links in text" that is checked by default. If you leave it checked, then your URL will be turned into a link when your post is published. If it is long, then the displayed text will be truncated. I do not know why the URL you included was not turned into a link.

    You can create an HTML hotlink by selecting the text for the link, clicking the "World Link" icon (middle of the middle row of icons) and then pasting the URL into the box. Your selected text will then become a link to that URL.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  7. #7
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to set variable in "for each cell in range" procedure

    All right Jeff.

    I've made some progress, and able to match pairs using VBA (newer version attached). But I Still need your help to order these results. I need all of them to populate column I rather than be written diagonally. Thanks

    ***Update*** in column G1 should be written: this is how column G should be look like" (rather than column A).
    Attached Files Attached Files
    Last edited by GIS2013; 09-11-2013 at 12:37 AM. Reason: Update

  8. #8
    Registered User
    Join Date
    12-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: How to set variable in "for each cell in range" procedure

    I still don't understand what you're trying to do, exactly. Previously you wanted to fill column B with matching pairs, but I could not understand what order you want the pairs in.

    What is in column A in your example versus Column G?

    The layout is also completely different. Please provide a "before" worksheet and an "after" worksheet.

    thanks

  9. #9
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to set variable in "for each cell in range" procedure

    @larai see my PM.

+ 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: 07-12-2013, 12:14 PM
  2. [SOLVED] Variable "sheet-name" and "range-name" wanted in INDEX/MATCH-function
    By Fiebuls in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-01-2012, 04:09 PM
  3. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 PM
  4. Running a procedure automitically if the value in a cell is "True"
    By tamrood2000 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-14-2007, 12:39 PM
  5. use variable in Workbooks("book1").Worksheets("sheet1").Range("a1"
    By Luc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2005, 04:05 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