+ Reply to Thread
Results 1 to 3 of 3

Macro does not function properly when I run through all work sheets

  1. #1
    Registered User
    Join Date
    11-12-2014
    Location
    Toronto
    MS-Off Ver
    MSO 2010
    Posts
    2

    Macro does not function properly when I run through all work sheets

    I'm running a basic code that will detect when certain columns stop having any data in their cells. I'm looking at the cells inside the area between K2 and W31.
    It seems to work when I focus in on one worksheet, but when I run the entire code, it returns a value of 5 for x ( which is not correct).
    I am wondering if someone might have an idea of what I was doing wrong, or what I should check.

    Thank you

    Code below:

    Sub Macro()
    Dim x, y, z, count As Integer
    count = 2

    x = 0
    y = 2
    z = 11

    Dim sheet As Worksheet


    For Each sheet In ThisWorkbook.Worksheets


    If sheet.Name <> "Main Analysis" Then
    count = count + 1


    For z = 11 To 23

    For y = 2 To 31

    If Cells(y, z) = "" Then x = x + 1 Else x = 0

    Next y

    Worksheets("Main Analysis").Cells(count, z) = x
    x = 0
    y = 2

    Next z
    z = 11

    MsgBox sheet.Name
    MsgBox count

    End If


    Next sheet


    End Sub

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro does not function properly when I run through all work sheets

    Please use code tags when posting code (see forum rule 3)

    The issue is that you didn't qualify the Cells call:
    Please Login or Register  to view this content.
    BTW if the idea is to count cells that are blank, the code won't work since it resets x every time it hits a non-blank cell.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    11-12-2014
    Location
    Toronto
    MS-Off Ver
    MSO 2010
    Posts
    2

    Re: Macro does not function properly when I run through all work sheets

    Thank you very much romperstomper. That was the error.
    Yes, but I would like to reset the count whenever there is a non-blank cell.

    Again, thank you for your help

+ 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. Getting the indirect function to work properly.
    By Kashus in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-05-2014, 08:49 PM
  2. offset function that I cannot get to work properly
    By deltaskelta in forum Excel General
    Replies: 5
    Last Post: 07-05-2012, 03:17 AM
  3. Can't get the HLOOKUP function to work properly
    By dennisvc in forum Excel General
    Replies: 1
    Last Post: 05-07-2012, 03:12 PM
  4. Match function won't work properly
    By oucivileng in forum Excel General
    Replies: 1
    Last Post: 04-23-2011, 04:24 PM
  5. [SOLVED] function does not work properly
    By lukiedukie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-22-2005, 06:06 PM

Tags for this Thread

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