+ Reply to Thread
Results 1 to 6 of 6

Manually changing specific items in code

  1. #1
    Registered User
    Join Date
    12-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Unhappy Manually changing specific items in code

    Hi Experts,

    I have recorded different macros which does following tasks for the same number of items, for example let’s call this items as A, B & C

    Macro-1:- Selects/deselects few items

    Example Code:-
    ActiveSheet.PivotTables("PV-2").PivotFields("Brand").CurrentPage = "(All)"
    With ActiveSheet.PivotTables("PV-2").PivotFields("Brand")
    .PivotItems("A").Visible = False
    .PivotItems("B").Visible = False
    .PivotItems("C").Visible = False
    End With


    Macro-2: Highlights the same items
    Example Code:- (For A only)

    Cells.Find(What:="A", After:=ActiveCell, LookIn:= _
    xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
    xlNext, MatchCase:=True, SearchFormat:=False).Activate
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 6662349
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With


    Macro-3: Enters this items in to a cell

    Example Code:-

    Range("T2").Value = "A"
    Range("T3").Value = "B"
    Range("T4").Value = "C"


    Macro-4: Finds and paste values of this items

    Example Code:- (For A only)

    Cells.Find(What:="A", After:=ActiveCell, LookIn:= _
    xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
    xlNext, MatchCase:=True, SearchFormat:=False).Activate
    ActiveCell.Offset(0, 7).Select
    Selection.Copy
    Sheets("Slide-14").Select
    Range("X6").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Macro-5 Deleting Entire row

    Example Code:- (For A only)

    Cells.Find(What:="A", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.EntireRow.Select
    Selection.Delete Shift:=xlUp



    Now that, the challenge is the specific list of items may change/add or remove items in future and each time I have to find this items in code and manually change it. Is there a way through which I can place a list of this items in some sheet and before running macro I just update the list and based on that the macro perform all this tasks above? So basically I want my macro to look at the updated list first and take those items only to perform above operations?

    Sorry if I have thought too long or I have not used proper terms, I have very basic knowledge of VBA and I was just wondering if there is some program for this.

    I really appreciate your time.

    Best,
    Bunty

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,054

    Re: Manually changing specific items in code

    Not sure if this is what you're looking for but you can declare A, B, and C as String and use them in your code as shown below. If you want to use a list to fill the values of A, B, and C you could do it by replacing (for instance)"Yes" with something like "Activesheet.range("X14").value"
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Manually changing specific items in code

    You might want to look into LOOPing. That is what you are trying to do.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  4. #4
    Registered User
    Join Date
    12-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Manually changing specific items in code

    Hi Jomilli,

    Thanks you so much for your reply. I tried your suggestion and I see an error message saying that "User-defined type not defined". I have attached the image for better idea.

    Test.png
    Please advice.

    Mike -I have separate macros for these tasks and also I have basic knowledge of VBA hence cant think of loop at this stage If I could just reference the names from sheets to my code (Wherever it is using) that would be great.

    Again, thank you both of you for your time. I really appreciate it.

    Best,
    Bunty

  5. #5
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Manually changing specific items in code

    I found this helpful when I was learning.
    http://www.excel-pratique.com/en/vba.php

    Also for your error you typed SRTING instead of STRING.

  6. #6
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,054

    Re: Manually changing specific items in code

    That's the best type of error, when you've just mispelled something. Easily fixed.

+ 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. Changing code to work on entire sheet instead of specific columns
    By elmasguapo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2015, 06:02 PM
  2. Need help changing a long formula without doing it manually
    By qlo_0lp in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-23-2015, 06:31 AM
  3. [SOLVED] How to Allow Both Picklist items and manually entered data in a cell
    By john quinn in forum Excel General
    Replies: 5
    Last Post: 01-09-2015, 05:16 PM
  4. [SOLVED] Macro to manually choose PDF file and save it to a specific location with specific name
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-18-2014, 07:47 AM
  5. Excel 2007 : Changing code to not be sheet specific
    By MiserableLawStdnt in forum Excel General
    Replies: 2
    Last Post: 10-10-2011, 09:41 AM
  6. Changing Search Code From Numeric Specific
    By laffers in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2011, 06:10 AM
  7. Timestamps of manually changing cells
    By Shadowmistress in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-15-2006, 07:56 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