+ Reply to Thread
Results 1 to 7 of 7

Looping thru columns for value

  1. #1
    Registered User
    Join Date
    11-14-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    96

    Looping thru columns for value

    Hello!

    In range("A2:Z20"), im trying to loop thru each column for cells containing a specific name ("joe dirt")
    How can i loop thru these columns, and if the column doesnt contain the name id delete it.

    Ive been experimenting & keep fumbling over multiple for loops. I figured id throw it out there, since this is the land of speedy experts. help me think on the right track, thank you in advance!!!

  2. #2
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Looping thru columns for value

    A somewhat slower implementation but simple enough that it should work

    Please Login or Register  to view this content.
    Edit: Misread column as row
    Last edited by smpita; 11-09-2017 at 04:04 PM.

  3. #3
    Registered User
    Join Date
    11-14-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Looping thru columns for value

    Thanks for the quick reply. Let me throw a scenario at you...

    I want to delete the column, and the column is comprised of dates. so just because the name doesnt appear on monday, doesnt mean i delete the entire column because it might appear just once at the end of the month. The entire column has to be blank in order to delete it.

    Update-question.
    I tried using a .Find method, as if i were looking thru the column for "joe dirt", then loop to next column. (however i couldnt make it work)
    Last edited by Quint6778; 11-09-2017 at 04:09 PM.

  4. #4
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Looping thru columns for value

    I'm not quite clear on what you're trying to achieve. Here is a copy of one of my primary search functions, it may be helpful to you.

    Use like this to return the string name of the range of all cells that loosely contain the string "joe dirt". Note, with explicit false it turn off case sensitivity and search within strings. It would match "Joe Dirty 11/16/2017" The return might look like the string "A2:Z20"

    Please Login or Register  to view this content.
    Use like this to return the first cell address that strictly contains the word "joe dirt". It will not match "Joe dirt". If "joe dirt" is not found, it will return the string "NotFound"

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by smpita; 11-09-2017 at 04:25 PM. Reason: TypeName(Me) used in the debug.print lines will break in some contexts. Removed for portability.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: Looping thru columns for value

    This may work, if I am understanding your issue correctly

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  6. #6
    Registered User
    Join Date
    11-14-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Looping thru columns for value

    This is exactly what i was looking for. Havent tested, but i'll make it work. i didnt even think of the COUNT function... thank you! and thank you smpita as well!

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: Looping thru columns for value

    You are welcome. Thanks for the rep.

+ 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] Looping through .Columns
    By efarkouh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-21-2017, 02:01 PM
  2. [SOLVED] Looping through columns
    By Peterhmg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-09-2016, 08:34 AM
  3. [SOLVED] Looping through columns
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-21-2016, 02:10 PM
  4. looping through columns
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2015, 08:59 PM
  5. Looping through columns
    By figuraluk in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-20-2013, 01:06 PM
  6. Do Until Looping (not looping through all other columns)
    By orle8050 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2013, 10:37 AM
  7. Looping thru columns
    By Robert in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-15-2005, 05:05 AM

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