+ Reply to Thread
Results 1 to 9 of 9

Targeting a workbook instead of just a column in VBS

  1. #1
    Registered User
    Join Date
    02-10-2016
    Location
    Wayne, NJ
    MS-Off Ver
    2016
    Posts
    21

    Targeting a workbook instead of just a column in VBS

    Hello,

    I have this line of code:

    Please Login or Register  to view this content.
    This is allowing my code to work, but only in column 1.

    How can I write this line, so that my code apply's to the entire sheet or workbook?

    Thank you!
    Babs

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Targeting a workbook instead of just a column in VBS

    Delete it.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Targeting a workbook instead of just a column in VBS

    Given the use of Target this is probably part of an Event-code. These Event-codes are restricted to the Sheet of which the Sheetmodule belongs to (where the code is placed).
    If you want this code to work for the entire workbook you will have to use an Event-code which is part of ThisWorkbook.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    02-10-2016
    Location
    Wayne, NJ
    MS-Off Ver
    2016
    Posts
    21

    Re: Targeting a workbook instead of just a column in VBS

    Hi Everyone,

    I am Ok with it just being the sheet. So, I think I can leave as is.......

    But deleting that line and getting rid of the "if" at the End "if" line since I was deleting the first "if" statement.

    Now even column 1 doesn't accept the code.

    Is there anyway to say instead of

    Please Login or Register  to view this content.
    Have it target every column?

    Thanks!
    babs

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Targeting a workbook instead of just a column in VBS

    Quote Originally Posted by sophielane View Post
    Hi Everyone,

    I am Ok with it just being the sheet. So, I think I can leave as is.......

    But deleting that line and getting rid of the "if" at the End "if" line since I was deleting the first "if" statement.

    Now even column 1 doesn't accept the code.

    Is there anyway to say instead of

    Please Login or Register  to view this content.
    Have it target every column?

    Thanks!
    babs
    Can you show the code for the entire procedure?

  6. #6
    Registered User
    Join Date
    02-10-2016
    Location
    Wayne, NJ
    MS-Off Ver
    2016
    Posts
    21

    Re: Targeting a workbook instead of just a column in VBS

    The codes part of another thread......
    This works but only in the column it seems to be targeting.

    thanks!



    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-10-2016
    Location
    Wayne, NJ
    MS-Off Ver
    2016
    Posts
    21

    Re: Targeting a workbook instead of just a column in VBS

    I figured out something that works:

    Please Login or Register  to view this content.
    seems to be working
    thanks!
    Babs

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Targeting a workbook instead of just a column in VBS

    Not to step on your achievement, but that If statement doesn't really do anything as it always evaluates as TRUE in the context of your code. It's equivalent to deleting the IF-End If lines.

    In your original code I deleted the If Target.Column = 2 Then -End If lines and the code worked for the whole sheet.

    Ultimately, this is how I would have written it.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-10-2016
    Location
    Wayne, NJ
    MS-Off Ver
    2016
    Posts
    21

    Re: Targeting a workbook instead of just a column in VBS

    Hi AlphaFrog,

    Works perfect, and it makes a little more sense to me, as a very very novice code person.

    Thank you!!
    Babs

+ 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. [SOLVED] Targeting Value and Copying Row to new sheet
    By evancruz in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-12-2015, 02:54 PM
  2. targeting variably named sheets
    By Coleman34 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-01-2014, 01:40 PM
  3. [SOLVED] Targeting Worksheet Name by Cell Value
    By daffodil11 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-21-2014, 05:04 PM
  4. Options targeting a specified total
    By santitobibenji in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-29-2014, 11:39 PM
  5. Targeting Multiple Workbooks using a Range to target by workbook an/or worksheet
    By daffodil11 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-18-2013, 04:02 PM
  6. [SOLVED] targeting another prg by using DDE in the code
    By CC_rider in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2006, 02:45 PM
  7. [SOLVED] Problems targeting any version of Excel
    By Larry Lard in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-19-2005, 08:06 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