+ Reply to Thread
Results 1 to 11 of 11

How to Insert text/formula in to cells based on the text in the cell beside

  1. #1
    Registered User
    Join Date
    04-08-2019
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    37

    How to Insert text/formula in to cells based on the text in the cell beside

    Hi,

    I have got a list of data in Sheet 2 that references cells in Sheet 1. I am using a couple of macros to insert rows and edit font/row sizes, etc. into Sheet 2.

    I now need to insert the formula "=IF(MOD(ROW(),1)=0,INDEX(Sheet1!$C$4:$C$49271,ROW()/2),"")" into the cell in column A of every newly created row.

    I will then need to insert a few new rules based on some other criteria. As this will then change the data that the above formula will reference, I need to copy and paste this information as a value before I do the next step.

    The macro I am using to create the rows is below with the cell I am trying to add this formula to highlighted in red. From what I can figure out there is no way to add the formula directly within this macro and I will need to run a new one, but I am honestly completely lost. Can anyone shed some light on what I should do?



    Please Login or Register  to view this content.
    Last edited by mikeymeteora; 02-25-2020 at 05:20 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: How to Insert text/formula in to cells based on the text in the cell beside

    Does this not work?
    Please Login or Register  to view this content.
    Notice the doubled-up quotation marks within the formula string. That's necessary to avoid the Formula = "..." string from being terminated prematurely.

    One other thing to note is that this needs to be in a standard module, not the Sheet1 or Sheet2 code module, otherwise it won't be able to amend a worksheet other than itself.

    If that doesn't help, it might be best to refer to the yellow band at the top of the page and attach a de-sensitised version of your workbook so we can see what's going on.

    HTH
    Tim
    Last edited by harrisonland; 02-25-2020 at 05:44 PM.
    Never stop learning!
    <--- please consider *-ing !

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,457

    Re: How to Insert text/formula in to cells based on the text in the cell beside

    Use

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Red face Re: How to Insert text/formula in to cells based on the text in the cell beside

    Jinx

  5. #5
    Registered User
    Join Date
    04-08-2019
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: How to Insert text/formula in to cells based on the text in the cell beside

    Yes this is exactly what I was trying to do, my inexperience with VBA is definitely showing.

    My 2nd issue is copying and pasting these cells as a value. I can manually just copy and paste all of column A to get a workable result for what I am doing but am hoping to find something that will only copy and paste those specific cells. Any help appreciated.


    (also is there a simple way to input a bottom border into these cells e.g. .Border = Bottom or something to that effect)
    Last edited by mikeymeteora; 02-25-2020 at 06:05 PM.

  6. #6
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: How to Insert text/formula in to cells based on the text in the cell beside

    How about this for the border...
    Please Login or Register  to view this content.
    I'm not quite sure what you want to copy/paste and where to. In general, you could perhaps adapt something like this:
    Please Login or Register  to view this content.
    Does that help move things along?

    Tim

  7. #7
    Registered User
    Join Date
    04-08-2019
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: How to Insert text/formula in to cells based on the text in the cell beside

    Yes that is exactly the border info I was looking for, thank you.

    The copy and pasting is literally into the same cells the inputted formula is already in. I just need to change it into a value so that when I run my next macro (that adds more rows) the information that was brought in form Sheet1 with that formula doesn't change.

    Perhaps something like this:


    Please Login or Register  to view this content.
    Last edited by mikeymeteora; 02-25-2020 at 07:01 PM.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,457

    Re: How to Insert text/formula in to cells based on the text in the cell beside

    You're welcome. Thanks for the rep.


    If you want to convert the formula you have just inserted, use:

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: How to Insert text/formula in to cells based on the text in the cell beside

    You can overwrite a formula with the resulting value like this:
    Please Login or Register  to view this content.
    Easy peasy!

    Tim

  10. #10
    Registered User
    Join Date
    04-08-2019
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: How to Insert text/formula in to cells based on the text in the cell beside

    Both of these are great but I have encountered an issue where adding this directly into my code causes it to reference the same cell multiple times. I suspect due to it activating too early in the code. I will mess around with it tomorrow using these new lines in different places to see if that helps.

    Thanks very much guys for your help guys. Definitely helped me move along greatly.

  11. #11
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: How to Insert text/formula in to cells based on the text in the cell beside

    You're quite welcome, and thanks for rep.

    Tim

+ 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 that moves cells with text, (up and to left, insert row/ insert copied cell)
    By sergi117 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-04-2018, 03:12 PM
  2. Formula to insert text in cell based on cryteria
    By nordicdust in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-05-2018, 07:58 AM
  3. Replies: 5
    Last Post: 03-21-2017, 10:30 PM
  4. Formula to insert text in a cell based on the date range of another cell
    By MTC2016 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-23-2016, 09:36 AM
  5. lock and insert formula in a cell based on selection of text in another cell
    By alirazafazal in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2014, 06:08 AM
  6. Formula to identify part of a text in cell from range of cells & insert adjacent cell text
    By Novicebutnotforlong in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-19-2013, 02:11 AM
  7. Replies: 4
    Last Post: 04-11-2011, 08:41 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