+ Reply to Thread
Results 1 to 4 of 4

What is str value in this simple code?

  1. #1
    Forum Contributor
    Join Date
    06-20-2021
    Location
    UK
    MS-Off Ver
    2016
    Posts
    126

    What is str value in this simple code?

    I am trying to understand what is the value of str especially when no initial state has been set.

    When I analyse in immediate window it shows the first value as str ="word|" and cell = "word"; but without setting str var first, how is this even possible?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: What is str value in this simple code?

    What is str? Where did you assign a value for it? As it is, it is empty

    Returns a Variant (Long) specifying the position of the first occurrence of one string within another

    Syntax

    InStr([ start ], string1, string2, [ compare ])

    The InStr function syntax has these arguments:
    Part Description
    start Optional. Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position. If start contains Null, an error occurs. The start argument is required if compare is specified.
    string1 Required. String expression being searched.
    string2 Required. String expression sought.
    compare Optional. Specifies the type of string comparison. If compare is Null, an error occurs. If compare is omitted, the Option Compare setting determines the type of comparison. Specify a valid LCID (LocaleID) to use locale-specific rules in the comparison.
    Last edited by AB33; 03-11-2022 at 01:55 PM.

  3. #3
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: What is str value in this simple code?

    str is being used to generate a unique set of cell values

    with each cell being iterated - if the cell value is not found in the str variable (Instr = 0) the cell value is appended to str such that if found again it is ignored.

    the final Split takes the resulting concatenation (of unique values) and splits them back out into unique items (c/o the pipe delimiter)

    you will often see people use the Dictionary Object to do the same thing...

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: What is str value in this simple code?

    Quote Originally Posted by immigrated4urjob View Post
    When I analyse in immediate window it shows the first value as str ="word|" and cell = "word"; but without setting str var first, how is this even possible?
    It isn’t. Until the str = str & cell & “|” line has been executed, str is an empty string.
    Rory

+ 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. [SOLVED] Speed up code? This simple VBA code makes me a report but its taking 20 minutes to finish
    By adamasmay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2022, 07:32 AM
  2. [SOLVED] Simple VBA code to convert text to number (simplify/fix current code)
    By kenenthpaul0401 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-26-2018, 10:47 AM
  3. Replies: 9
    Last Post: 05-21-2018, 04:34 PM
  4. [SOLVED] Please tell me simple search vba code ? my vba vlookup code not working..
    By aliakbaram85 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-27-2018, 01:54 AM
  5. Need help with relatively simple VBA code.
    By super1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2013, 11:23 AM
  6. [SOLVED] Need code for simple IF-Then
    By excelnut1954 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-17-2005, 04:25 PM
  7. help on this simple code... or not so simple?
    By bondcrash in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-18-2005, 07:25 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