+ Reply to Thread
Results 1 to 6 of 6

Insert columns upon criterias

  1. #1
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Birmingham, UK
    MS-Off Ver
    2007
    Posts
    185

    Insert columns upon criterias

    Hello,

    I have got a sheet that is loading reports and needs to calculate data from a certain point of the spreadsheet (column with certain day).

    What I want Macro to do is to check a G2 location of it starts with certain 2 letters to determine how many columns I need to insert in front of it to make sure that the rest of the macro and calculations are working correctly. This to make sure I can always find Monday's data in the same location.

    I am hoping that someone knows what code to use to determine the conditions - I know what is the code for the column insertion but do not know how to make it conditional.

    I am attaching a sample file with a little explanation in it as well.

    I appreciate your effort and any tries to make it work and want to thank you all for having a go at it. I really do not know how to work it out.

    Thank you in advance.

    Simon
    Last edited by Ramzes; 08-25-2016 at 06:36 AM.
    ...and this is when I walk in, dressed fully in white...

  2. #2
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Insert columns upon criterias

    Goood morning,

    Here you go.

    Please Login or Register  to view this content.
    Please consider:
    Be polite. Thank those who have helped you.
    Click the star icon in the lower left part of the contributor's post and add Reputation. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .
    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Posting code between tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

  3. #3
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Birmingham, UK
    MS-Off Ver
    2007
    Posts
    185

    Re: Insert columns upon criterias

    Hi,

    Thank you very much for your help.

    I have got a little trouble though. It worked perfectly on a sample file.

    In my original one I am inserting data from text file. it looks then exactly alike as per the attached sample but about 2000 rows and 50 columns.

    In the original file it seems to be checking H2 instead of G2 despite the fact that the code is clearly stating G2 and G:G but inserts before H.

    I have change the range to F2 so that it reads the G2 and columns from G:G to F:F to make it work and it seems I succeeded.

    Would you have any ideas why this is working this way?

  4. #4
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Insert columns upon criterias

    Hi there,

    I created an if function in order to check all the time the value from cell G2.
    If you want to check H2 then you can customize the code in order to check H2.

    The line that has to be changed is: ' Lresult = Left(Range("H2").Value, 2) ' instead of H2 you can change it in order to check other cell, if you need other cell and not G2.

  5. #5
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Birmingham, UK
    MS-Off Ver
    2007
    Posts
    185

    Re: Insert columns upon criterias

    Hello,

    Thank you for your reply.

    I have noticed it is customisable.

    I do want it to look in G2 although what I meant is that in my main file I asked it to look into G2 but it was taking values from H2 for some reason.

    it must be a "ghost in a machine".

    Thank you once again for your help.

  6. #6
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Insert columns upon criterias

    Hi Ramzes,

    If the answer provided is what you needed.

    Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done.
    If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

+ 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] Sumifs Two Criterias from different columns
    By lexusap in forum Excel General
    Replies: 5
    Last Post: 03-31-2015, 04:43 AM
  2. [SOLVED] Averaging Columns Containing 0s Based On 2 Criterias
    By mattdh12 in forum Excel General
    Replies: 4
    Last Post: 10-13-2014, 10:38 AM
  3. adding multiple columns with 2 criterias
    By kaiserksk in forum Excel General
    Replies: 2
    Last Post: 03-02-2012, 05:57 PM
  4. How to insert data in a new worksheet based on criterias
    By newbie_25 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-21-2010, 09:14 PM
  5. counting from columns using criterias
    By funkymonkUK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-24-2007, 09:52 AM
  6. [SOLVED] Need function for one value for two criterias and two columns
    By Melanie in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-14-2006, 12:45 AM
  7. [SOLVED] Why can't i filter two different columns with different criterias like this
    By Claus in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-09-2005, 10:05 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