+ Reply to Thread
Results 1 to 3 of 3

Grabbing text by iterating through multiple cells?

  1. #1
    Registered User
    Join Date
    05-08-2017
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    81

    Grabbing text by iterating through multiple cells?

    Hi,

    Simple issue. I want to go through a series of rows in a column ("A") and check if they contain a certain string. If so, they should set a variable to 1, else to -1. I understand that the value property cannot grab values for multiple cells. However, I tried using For Each to hopefully try and get around this, but VBA seems to still be missing the string even though it's contained in the row it iterates through (which ends up producing -1 in the message box).

    Code as follows:

    Please Login or Register  to view this content.
    Note that if I replace Range("A:A") with Range("A3") (the cell that contains the word "Doc"), it returns 1 which means it worked.

    Thanks in advance for any help!

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Grabbing text by iterating through multiple cells?

    Your code is checking over a million rows for a value. You should probably narrow the range to just the used cells (either by UsedRange or by finding the last used cell in column A). Also, the MsgBox code is outside the For/Next loop, so it will only show the last value it contained. Since the last cell it tested was A1048576 (likely blank), it will return -1.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-08-2017
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    81

    Re: Grabbing text by iterating through multiple cells?

    Thank you @Paul.

    I see there's several mistakes in the code you've pointed out. It works as expected now. Will definitely be mindful of making sure the search is narrowed down!

+ 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. Iterating through Cells In a column
    By Cnelson0789 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2018, 10:58 PM
  2. Iterating over column and pasting that information into text box on web
    By dookie418 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2016, 10:55 AM
  3. Replies: 1
    Last Post: 04-14-2011, 09:24 AM
  4. Grabbing cells with text from a range
    By Plaasboy in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-10-2008, 06:32 AM
  5. Macro Iterating through multiple cols and Creating a Strings
    By kaitewright in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2008, 05:03 AM
  6. Iterating through discrete multiple column selections.
    By excel_m in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2007, 03:48 PM
  7. [SOLVED] Iterating through cells, comparing values
    By kingpin2502 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-11-2005, 02: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