+ Reply to Thread
Results 1 to 5 of 5

Macro that runs on entire column - not stopping on blanks

  1. #1
    Registered User
    Join Date
    06-11-2009
    Location
    Swe
    MS-Off Ver
    Excel 2003
    Posts
    27

    Macro that runs on entire column - not stopping on blanks

    Hi,
    I've got a column with some blanks in it, which I want to run a macro on.
    How do I tell it to run on the entire column, all the way to the last value, without stopping on the first blank cell?

    Here's my macro.
    Public Sub MyMacro()
    Dim rngCell As Range
    Set ws2 = Workbooks("a.xls").Sheets("Sheet2")
    For Each rngCell In ws2.Range(Cells(2, "C"), ws2.Cells(Rows.Count, "C").End(xlUp)).Cells
    If rngCell.Offset(, 1).Value = "A" Then
    With rngCell
    .Value = "AAA"
    End With
    End If
    Next rngCell
    End Sub

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro that runs on entire column - not stopping on blanks

    Is your Coulmn C? If so your code should not be affected by blanks, this works
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-11-2009
    Location
    Swe
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Macro that runs on entire column - not stopping on blanks

    Is your Coulmn C?
    yep

    If so your code should not be affected by blanks, this works
    Oh, you're right. It did! (see now that i had another problem with my code that was causing it to malfunction)

    However, I have a different variant of this macro, that doesn't seem to work.
    The only difference is that it checks for a color instead of a value.
    But for some reason, this does not work. It stops on the first blank cell in C.
    Public Sub MyMacro()
    Dim rngCell As Range
    Set ws2 = Workbooks("io.xls").Sheets("IO-List")
    For Each rngCell In ws2.Range(Cells(2, "C"), ws2.Cells(Rows.Count, "C").End(xlUp)).Cells
    If rngCell.Offset(, 1).Interior.ColorIndex = 15 Then
    With rngCell
    .Value = "AAA"
    End With
    End If
    Next rngCell
    End Sub
    Last edited by dadel; 07-27-2009 at 07:03 AM.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro that runs on entire column - not stopping on blanks

    Your code works so either the colour is not 15 or there is another problem.

    Also, you do not declare ws2 as a variable. Again this code is neater
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-11-2009
    Location
    Swe
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Macro that runs on entire column - not stopping on blanks

    OK. Just found out that the problem is that that I'm using Conditional Formatting to color the cells.

    And for some reason coloring with conditional formatting does not change the interior color index of a cell.

    How annoying.
    Also, you do not declare ws2 as a variable. Again this code is neater
    thanks for the tip.
    Last edited by dadel; 07-27-2009 at 07:14 AM.

+ 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