+ Reply to Thread
Results 1 to 6 of 6

Format cell in For each loop problem

  1. #1
    Registered User
    Join Date
    03-12-2015
    Location
    Denver
    MS-Off Ver
    2010
    Posts
    8

    Format cell in For each loop problem

    I am a novice user of VBA and new to excel vba. I am trying to run a range through a loop, and format the active location based on a vlookup. The code is listed below works with the exception of the 2 lines that are supposed to format the cell that was read ( V.Address.Interior.ColorIndex = 37). I believe i am useing the .Address wrong. How do i tell this format line to format the range that is active in the for loop. I have searched quite a bit online but must be using the wrong words to find the answer.

    Thank you so much for the help


    Please Login or Register  to view this content.

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Format cell in For each loop problem

    Just get rid of the Address altogether. The location is implied.

    Please Login or Register  to view this content.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,616

    Re: Format cell in For each loop problem

    If I understood well and you need to format cells in A1:AB58 of current sheet, then simple
    Please Login or Register  to view this content.
    etc. would do.
    Best Regards,

    Kaper

  4. #4
    Registered User
    Join Date
    03-12-2015
    Location
    Denver
    MS-Off Ver
    2010
    Posts
    8

    Re: Format cell in For each loop problem

    I am looking to format just the cell that is currently running through the loop. I changed my code and eliminated the .address but nothing changed. My calculations are working but nothing is getting formatted. Is it something with excel 2010 or is there an option that could be preventing the format from VBA?

  5. #5
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Format cell in For each loop problem

    Perhaps change the dimension of V and ArrIn to Range instead of Variant.

    The 'For Each' structure only works on Collections and Arrays, and while you're searching for a Variant object in the Array, it translates more literally to a Range in the Range.

    When my variables break, I first eliminate On Error code so I can capture what's occuring. Next, I remove my implied variables and state them explicitly.

    I'd comment out and begin with:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-12-2015
    Location
    Denver
    MS-Off Ver
    2010
    Posts
    8

    Re: Format cell in For each loop problem

    Worked perfectly. Thank you very much for your insight

+ 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: 5
    Last Post: 01-28-2015, 10:49 PM
  2. [SOLVED] Double 'For Each Cell' loop range problem
    By gombi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-20-2014, 02:25 PM
  3. Vlookup problem in a loop with cell property and variable cell problem (long title sry)
    By ExcelsiorLux in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2013, 10:38 AM
  4. [SOLVED] Macro to loop through cell values in a column and format multiple cell values
    By Roop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2012, 05:39 PM
  5. VBA Code - multiple cell loop to txtbox Question/Problem
    By IanZernechel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-05-2012, 04:06 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