+ Reply to Thread
Results 1 to 7 of 7

Edit a working macro so it can check a value in a cell

Hybrid View

  1. #1
    Registered User
    Join Date
    01-15-2015
    Location
    Oporto, Portugal
    MS-Off Ver
    Microsoft professional Plus 2010
    Posts
    3

    Edit a working macro so it can check a value in a cell

    Good day to all in first place

    I am new to VBA and need some help to edit a working macro so it can check a value in a cell, I do this process ever month for 500 sheets (same sheet just changes month and employer name)

    Example of what is working at the moment:

    Sub Imprimir()
    With Worksheets("Francisco")
    With .Range("L4")
    If IsNumeric(.Value) Then
    .Value = .Value + 1
    .Parent.PrintOut preview:=False
    Else
    MsgBox "Cell isn't numeric!"
    End If
    End With
    End With
    End Sub

    Now what I need is to check if cell (D4) has text(employer name) or ( 0 ) 0=employer no longer works with us there for don't need to print

    Hope the information is enough
    Thanks a lot!!!!

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,038

    Re: Edit a working macro so it can check a value in a cell

    In your code you test the value of L4 but in your explanation you say you want to check D4. Which cell do you want to check? You want to check the cell if it contains the number 0. Is this correct?
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    01-15-2015
    Location
    Oporto, Portugal
    MS-Off Ver
    Microsoft professional Plus 2010
    Posts
    3

    Re: Edit a working macro so it can check a value in a cell

    Quote Originally Posted by Mumps1 View Post
    In your code you test the value of L4 but in your explanation you say you want to check D4. Which cell do you want to check? You want to check the cell if it contains the number 0. Is this correct?
    Sorry for the bad explanation, cell ("L4") looks up the employer name and fills the name in cell ("D4") but if ("L4") name is blank it puts a 0 in cell ("D4").
    But the same worksheet prints from 1 - 500 only changing the employer nš ("L4") and Name ("D4").

    Conclusion: when I press ctrl+p it prints but if ("D4") is 0 then it still adds 1 to ("L4") even if it does not print
    Last edited by fjrlopes; 01-16-2015 at 05:13 AM.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,038

    Re: Edit a working macro so it can check a value in a cell

    If you simply want to increase the value of L4 by 1 if D4=0 then this would do it.
    Sub Imprimir1()
        If Sheets("Francisco").Range("D4") = 0 Then
            Range("L4") = Range("L4") + 1
        End If
    End Sub
    I don't think that I am clear on what you want to do. It would be easier to understand if I could see your data. Could you attach a copy of your file and include a detailed explanation referring to specific cells and worksheets.

  5. #5
    Registered User
    Join Date
    01-15-2015
    Location
    Oporto, Portugal
    MS-Off Ver
    Microsoft professional Plus 2010
    Posts
    3

    Re: Edit a working macro so it can check a value in a cell

    Firstly I want to thank you for the intresste in helping out.

    Let me see if I can explain the situation,

    the sheet starts 0 on ("L4")every month if you tell it to print it prints the sheet and automatically changes ("L4") to the next nš. 1,2,3,4,ect.
    when you get to a number where sheet "Funcionarios" has no name in cell ("D4") appears a 0.

    That I want is where ("D4")=0 don't print but pass ("L4") to next number
    Attached Files Attached Files

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,038

    Re: Edit a working macro so it can check a value in a cell

    Try this code:
    Sub Imprimir1()
        If Sheets("Francisco").Range("D4") = 0 Then
            Range("L4") = Range("L4") + 1
        Else
            MsgBox ("Print")
            Range("L4") = Range("L4") + 1
        End If
    End Sub
    change the msgbox line to your print command line.

+ 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. Edit a working macro so it can check a value in a cell
    By fjrlopes in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 01-15-2015, 02:12 PM
  2. Vba macro check and add records from working file to other workbooks
    By Jovillanueva in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2014, 12:40 PM
  3. [SOLVED] Spell check macro not working :(
    By AdamJaffrey in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-03-2013, 05:52 PM
  4. [SOLVED] Allow users to edit ranges not working after running a Macro?!
    By Margate in forum Excel General
    Replies: 2
    Last Post: 02-15-2013, 07:42 AM
  5. Check cell...if not empty copy row (EDIT FOR ADDITIONAL PROBLEM)
    By skip08 in forum Excel - New Users/Basics
    Replies: 11
    Last Post: 09-13-2011, 10:29 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