+ Reply to Thread
Results 1 to 21 of 21

VBA to Add Column to Table Based on Value in Cell

  1. #1
    Registered User
    Join Date
    01-07-2018
    Location
    London
    MS-Off Ver
    13
    Posts
    39

    VBA to Add Column to Table Based on Value in Cell

    Hi all,

    I am working on creating a table for calculating daily rate and margin for a company. We are currently working with several rates. However, in the near future there is a chance for adding one on two more. Attached is part of the example for the first page. Now I cannot figure out which formula to put to automatically populate the field "column1" when we enter new rate, not listed already. Can it be done without using VBA? I was considering conditional IF function with match for all the previous cells.
    Any ideas will be appreciated.

    Thank you in advance
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    07-22-2016
    Location
    Cordova
    MS-Off Ver
    2007
    Posts
    44

    Re: If function needed

    How do you want to calculate daily rate and margin ?

  3. #3
    Registered User
    Join Date
    01-07-2018
    Location
    London
    MS-Off Ver
    13
    Posts
    39

    Re: If function needed

    I already have all the formulas for them set up I am lacking only this bit. I just the number entered under daily rate on the left to be shown in the last column ("column1"). I am not sure i explained that one clearly before.

  4. #4
    Registered User
    Join Date
    07-22-2016
    Location
    Cordova
    MS-Off Ver
    2007
    Posts
    44

    Re: If function needed

    You can just write = then choose your cell you want to show its content
    But I am not sure too that I understand your request

  5. #5
    Registered User
    Join Date
    01-07-2018
    Location
    London
    MS-Off Ver
    13
    Posts
    39

    Re: If function needed

    I wanted a check for repeating values.

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: If function needed

    Sorry, but Im having a hard time understanding what you want to do here

    What is "column 1" supposed to be doing and how does it fit in what what you have there? You said you had some formulas there, I cant see any?
    Can you some some examples of what you expect??
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,434

    Re: If function needed

    So, each time you change the rate in D3, you want a new column to be added to the table with that value as its header like this:

    Excel 2016 (Windows) 32 bit
    I
    J
    K
    L
    M
    N
    2
    Day rate
    £550
    £560
    £570
    £575
    £900
    3
    Revenue
    £399,300
    £406,560
    £413,820
    £417,450
    4
    Margin
    18.40%
    19.86%
    21.27%
    21.95%
    Sheet: Sheet1

    Is that it?
    Last edited by AliGW; 04-09-2018 at 02:30 AM. Reason: Typo.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  8. #8
    Registered User
    Join Date
    01-07-2018
    Location
    London
    MS-Off Ver
    13
    Posts
    39

    Re: If function needed

    HI Ali,

    Sorry for the late reply. Yes that is exactly what I want. If possible with check for matching with previous numbers.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,434

    Re: If function needed

    OK - well, you will need VBA for this. I cannot help you myself, but can move the thread to the correct forum section for you, which I shall do now.

    I've also updated your thread title: in future, please make your thread titles much more specific and explicit.

  10. #10
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: VBA to Add Column to Table Based on Value in Cell

    Perhaps this in the worksheet's code module
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,434

    Re: VBA to Add Column to Table Based on Value in Cell

    Does it need the line about adding the £ sign if the cell is already formatted to show it?

  12. #12
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: VBA to Add Column to Table Based on Value in Cell

    As written, yes- the Value property will ignore formatting. We could simply use the Text property though, if the format of D3 matches the way the column headers should look.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,434

    Re: VBA to Add Column to Table Based on Value in Cell

    Interesting - thanks.

  14. #14
    Registered User
    Join Date
    01-07-2018
    Location
    London
    MS-Off Ver
    13
    Posts
    39

    Re: VBA to Add Column to Table Based on Value in Cell

    @Ali Thank you very much, I will keep in mind your tip regarding the heading.

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,434

    Re: VBA to Add Column to Table Based on Value in Cell

    Has the code provided in post #10 worked for you?

  16. #16
    Registered User
    Join Date
    01-07-2018
    Location
    London
    MS-Off Ver
    13
    Posts
    39

    Re: VBA to Add Column to Table Based on Value in Cell

    Hi xlnitwit,
    as I am quite new to VBA. Can you please tell me what should I do after adding the code at the worksheet code module.

    Thank you in advance for your cooperation.
    Last edited by Sammydasalmon; 04-09-2018 at 04:02 AM.

  17. #17
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VBA to Add Column to Table Based on Value in Cell

    Hello
    You should save the workbook to the extension xlsm or xlsb which supports the macros
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  18. #18
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: VBA to Add Column to Table Based on Value in Cell

    As YasserKhalil said, you'll need to save the workbook in a macro-enabled format, but other than that, just change the value in D3 and you should see the table add a new column as appropriate.

  19. #19
    Registered User
    Join Date
    01-07-2018
    Location
    London
    MS-Off Ver
    13
    Posts
    39

    Re: VBA to Add Column to Table Based on Value in Cell

    I inserted the code into the workbook and now are trying to start it, but still facing issues. I believe the code is fine the problem is in my skills. I will check some video to get a better idea of how to make it running.

  20. #20
    Registered User
    Join Date
    01-07-2018
    Location
    London
    MS-Off Ver
    13
    Posts
    39

    Re: VBA to Add Column to Table Based on Value in Cell

    Ladies and gents thank you all for the help. Issue SOLVED, the code provided is working perfect.

    Thank you all for the fast responses.

  21. #21
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,434

    Re: VBA to Add Column to Table Based on Value in Cell

    Good to know.

+ 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. Replies: 4
    Last Post: 03-30-2017, 09:52 AM
  2. find a cell in a table based off column and row criteria
    By ctryporboy in forum Excel General
    Replies: 2
    Last Post: 02-08-2016, 05:17 PM
  3. Replies: 0
    Last Post: 02-16-2015, 04:54 PM
  4. [SOLVED] Fill a cell in Column B based on the text in Column A using a table on sheet 2
    By lbrasfie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-25-2013, 01:56 PM
  5. vba code to filter pivot table column labels based on cell vaule
    By nailler167 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-31-2013, 09:12 PM
  6. Lookup Column number in a table based on a cell value
    By electricmice in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-22-2012, 01:08 AM
  7. Writing to cell in table based on column and row names
    By teacher_rob in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2011, 11:17 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