+ Reply to Thread
Results 1 to 5 of 5

VBA code help - several actions in one code + declaring and using a variable

  1. #1
    Registered User
    Join Date
    08-23-2013
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    3

    VBA code help - several actions in one code + declaring and using a variable

    *** I solved this issue! Thanks to anyone that may have looked and pondered here. ***


    Hi all!

    I have been struggling with this code for a few hours now.. it seems like I cannot get it to work at all.

    The code itself is probably not the best, as I've written is by piecing together my own logic + some things I've picked up from various forums.

    Here is the code, followed by an explanation of what I want to do with it:
    Code:

    Please Login or Register  to view this content.
    Explanation:
    There is a button on sheet 1 that will activate this code. Once activated, it will search Sheets 9, 10, and finally 11 for a value in cell E2 (only one of the three sheets will have a value in it), and rename sheet 6 with that value. If no values are found, it will rename the sheet with "#Error#". So far, it renames the sheet to "#Error#" regardless if there is entries in one of the 3 sheets' E2 cells or not.

    From here, it will go to the sheet named "PartPoQty" (sheet 5) and refresh the pivot table there (was working fine for me, but stopped working as well).

    Finally, it will go to the first sheet, name "PalletLabel". Here is where I'm having the biggest issues. On this sheet in cell B1 is a value that tells me how many pallet labels I need (example, 25). This number will change every time the code is run because this workbook is for sales invoices, and different information will be put in to the spreadsheet whenever it is used, which will result in this number being calculated differently every time. It will always be a non-zero integer between 1-35ish. What I'm trying to do with the last few lines of code is have Excel autofill the value in cell A2 (so that it increases by one each cell.. works manually) for x number of cells, where x = cell B1's value.

    Example, if B1 = 25 = number of pallet labels I need, A2 will be filled down 24 rows to create 25 unique pallet labels (PPP1000001, PPP1000002, ..03, ..04, etc).


    It should be worth mentioning that although the first part, ie checking for values amidst the last 3 sheets and renaming sheet 6, is not a necessity but more of a luxury. The most important thing is the last part, ie filling down column a x times.

    If it were at all possible, too, actually.. the value for cell A2 that gets filled is a value in the format of PPPxxxxxx, where each x is a number. This is copied over from another workbook, which we will call "Pallet#s". Is there any way to import this number from the last entry in Column H of that workbook into cell A2, then use it to fill down?

    Thank you all for your time.
    Anthrax

    Edit: Cross-posted on
    HTML Code: 
    Excelfox for higher traffic. This is urgent- work related, and will be monitored actively.
    Last edited by anthrax899; 08-23-2013 at 01:47 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code help - several actions in one code + declaring and using a variable

    Why are you referring to ActiveSheet throughout the code and not using the variable Ws?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-23-2013
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: VBA code help - several actions in one code + declaring and using a variable

    Quote Originally Posted by Norie View Post
    Why are you referring to ActiveSheet throughout the code and not using the variable Ws?
    I`m not entirely sure. I generally record a macro and then edit it and add on to it based on what it starts me off with. As I said, I don't have much-if any experience with macros.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: VBA code help - several actions in one code + declaring and using a variable

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    Cross Post: http://www.excelfox.com/forum/f2/vba...variable-1400/
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    08-23-2013
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: VBA code help - several actions in one code + declaring and using a variable

    Quote Originally Posted by alansidman View Post
    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    Cross Post: http://www.excelfox.com/forum/f2/vba...variable-1400/
    Fixed on both sites- sorry..

+ 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. VBA Code to return a summary sheet of due actions
    By ambquinn in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-13-2011, 04:15 AM
  2. How do you combine code that requires different Sub Worksheet actions?
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 34
    Last Post: 09-29-2010, 11:11 AM
  3. Code Reuse - Logging Actions When a Cell Changes -2
    By webbug08 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-02-2009, 04:35 PM
  4. Code Reuse - Logging Actions When a Cell Changes
    By webbug08 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-02-2009, 06:23 AM
  5. [SOLVED] Repeat Code Repetitive Actions?
    By chris in forum Excel General
    Replies: 2
    Last Post: 02-18-2005, 08:06 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