Results 1 to 3 of 3

Adjust a macro to check for content of a cell and then run a macro on target sheet

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-18-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2010
    Posts
    139

    Adjust a macro to check for content of a cell and then run a macro on target sheet

    Hey guys,

    I need help with adjusting my macro. Basically it opens a file and then copies content. However before doing the copying, I want it to check if on the file it opened whether the content of G1 is "pass". If it is pass to run the macro "Adjust" on that workbook.

    How do I do that? I tried with:
    If ActiveWorkbook.Worksheets("Target").Cell("G1") = "pass" Then Application.Run ActiveWorkbook.Name & "!Adjust"
    but it gives me an error

    Option Explicit
    Sub test()
        Dim wb As Workbook, wb2 As Workbook
        Dim ws As Worksheet
        Dim vFile As Variant
    
        'Set source workbook
        Set wb = ActiveWorkbook
        'Open the target workbook
        vFile = Application.GetOpenFilename("Excel-files,*.xls", _
            1, "Select One File To Open", , False)
        'if the user didn't select a file, exit sub
        If TypeName(vFile) = "Boolean" Then Exit Sub
        Workbooks.Open vFile
        'Set targetworkbook
        Set wb2 = ActiveWorkbook
    
    If ActiveWorkbook.Worksheets("Target").Cell("G1") = "pass" Then Application.Run ActiveWorkbook.Name & "!Adjust"
    Thank you in advance!

    P.S.:
    Okay, found it. It works fine this way:
    If ActiveWorkbook.Worksheets("Target").Range("G1").Value = "pass" Then Application.Run ActiveWorkbook.Name & "!Adjust"
    Last edited by dreddster; 10-17-2013 at 07:24 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 10-28-2012, 01:13 AM
  2. Adding Dynamic Comments based on the Target Cell Content..using a MACRO..
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-20-2012, 04:14 AM
  3. Replies: 1
    Last Post: 02-19-2007, 04:52 PM
  4. [SOLVED] macro to find cell content in sheets and make sheet active
    By Nigel in forum Excel General
    Replies: 3
    Last Post: 11-18-2005, 05:00 PM
  5. [SOLVED] How to check a cell for content before running macro.
    By Incoherent in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2005, 12:05 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