+ Reply to Thread
Results 1 to 9 of 9

Search cell

  1. #1
    Registered User
    Join Date
    05-20-2010
    Location
    Green Bay
    MS-Off Ver
    Excel 2007
    Posts
    20

    Search cell

    I have a macro that I am trying to get something done. I want it to search a range of cells from E2:P13. If it contains a "1" then copy cell B27 to that cell and repeat for all cells in that range. If it contains a "2" then copy cell C27 to that cell.

    I had a VB class in college and wrote this, but I would have to copy and paste it for each cell and if I add a row it would not be easy to change.

    Please Login or Register  to view this content.
    Can anyone help with something more "dynamic"?

    Thanks!
    Last edited by esullivan; 05-20-2010 at 11:23 AM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro Help

    You can loop through cells using a Range object like this:

    Please Login or Register  to view this content.

    Hope it helps,

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    05-20-2010
    Location
    Green Bay
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Search cell macro help

    So how would I tell it do paste in the cell it's found a match for? I am sorry, I know BASIC VB, but this is kind of over my head.

    Thanks

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Search cell

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-20-2010
    Location
    Green Bay
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Search cell

    Like this?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Search cell macro help

    Quote Originally Posted by esullivan View Post
    So how would I tell it do paste in the cell it's found a match for? I am sorry, I know BASIC VB, but this is kind of over my head.

    Thanks
    Did you try the code I posted? It should do everything you described in your original post.

    Dom

  7. #7
    Registered User
    Join Date
    05-20-2010
    Location
    Green Bay
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Search cell

    Oh wow, yeah it does thanks. Except it on;y copies the value not the formatting. I have fill colors and text colors that need to be changed.

    Thanks again for all your help by the way!
    Last edited by esullivan; 05-20-2010 at 05:40 PM.

  8. #8
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Search cell

    Try this:

    Please Login or Register  to view this content.

    Dom

  9. #9
    Registered User
    Join Date
    05-20-2010
    Location
    Green Bay
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Search cell

    That worked great! Thanks man!!!!

+ 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