+ Reply to Thread
Results 1 to 6 of 6

Shorten VBA Code

  1. #1
    Forum Contributor
    Join Date
    01-15-2015
    Location
    philippines
    MS-Off Ver
    Excel 365
    Posts
    116

    Shorten VBA Code

    Hi Guys,

    I need help shortening this VBA code.
    The code will copy a certain value, then paste it to a certain cell in a certain tab.
    The values are placed in a table. This table is in a tab called "Main".

    The table contains:
    Column F = names of the tabs
    Column G = value to be pasted
    Column H = the location of the cell from which the values are to be pasted

    You may see attached image.

    The tabs range from 1 to 100.
    The code below is what I have written. Though it's just a portion of the whole code, you should get the idea by simply 1.pnglooking at it.
    It starts off by copying the value adjacent to "1", then paste it on tab "1", on the cell location stated in column "H" of the table for the said tab name.
    It goes on from tab 1 until it reaches tab 100.
    The code I came up with is lengthy, so I need help to make it better.
    Thank you in advance.


    Please Login or Register  to view this content.
    Attached Images Attached Images
    Last edited by AliGW; 01-21-2021 at 04:05 AM.

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,523

    Re: Shorten VBA Code

    Don't know if I understood your request right, so make sure to try on a copy of your workbook. (as you should always do anyway)
    You mention table, but I don't see anything in your code that you have an actual table, just a Range.
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    01-15-2015
    Location
    philippines
    MS-Off Ver
    Excel 365
    Posts
    116

    Re: Shorten VBA Code

    Hi Jolivanes,

    Thank you for looking into this.
    I'm sorry I meant a range. Not a table.
    Your code has an extra ) on the second line, just before .Value.
    But I tried it after removing the extra ).
    It doesn't seem to do the desired result.
    I have attached a simplified copy of the file.
    The real file is really big, so I had to make it uploadable here.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Shorten VBA Code

    Hi
    Try
    Please Login or Register  to view this content.
    Last edited by mohadin; 01-21-2021 at 05:29 AM.

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,523

    Re: Shorten VBA Code

    How is the data in Column A in all your sheets entered and where is that coming from?
    Is the Tab Reference always the next empty cell in Column B for all the sheets?

    BTW, here is the fixed code. I was in too much of a hurry to go and rest. Have not tried it on your attachment though. Just a general solution.
    If you are going to try/use it, change references if and where required.
    But I think, I have not tried it, mohadin has you covered on that.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    01-15-2015
    Location
    philippines
    MS-Off Ver
    Excel 365
    Posts
    116

    Re: Shorten VBA Code

    Hi mohadin,

    Your code is great. It does the basic task of pasting the intended values into their respective tabs.
    The only problem is, it also pastes the info from column "H", which is not required. But this is my fault since my instructions were not clear enough.
    I just did a very little change to the code and it was able to do the required.

    Hi jolivanes,

    Your code is great, works perfectly.

    I would be saving both codes for future reference and backup.
    Thank you both for helping.

+ 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] Shorten VBA code
    By DiCaver in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2018, 05:40 AM
  2. [SOLVED] Represent (define?) a section of code with a variable (shorten long code lines)?
    By Gene@action in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-01-2016, 03:59 PM
  3. [SOLVED] How to Shorten my VBA Code?
    By JRidge in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2014, 06:07 AM
  4. [SOLVED] Very inefficient code because of different sizes of arrays, how do i shorten my code?
    By Brammer88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 04:49 PM
  5. How to shorten the code?
    By joyce_88 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2008, 06:37 PM
  6. shorten my code
    By joyce_88 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-01-2008, 01:55 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