+ Reply to Thread
Results 1 to 4 of 4

Adding a name\word to a range of cells without deleting the data already in each cell.

  1. #1
    Registered User
    Join Date
    12-13-2023
    Location
    Melbourne
    MS-Off Ver
    Office 365
    Posts
    5

    Adding a name\word to a range of cells without deleting the data already in each cell.

    Hi I am trying to find a way for adding a name\word to a range of cells without deleting the data already in each cell.

    I can sort of get it working by..


    Adding two spaces to the end of the data in each cell.
    Selecting the cells I want to add a word to.
    Use find and replace to find two spaces then replace with the word\name with two spaces after the name.
    This works, but if a cell in the range has no data, excel wont leave a cell blank with two spaces. The spaces disappear. So find and replace does not work for blank cells.

    Wondering if there is another way to add a word to the end of the data in a bunch of selected cells?
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,047

    Re: Adding a name\word to a range of cells without deleting the data already in each cell.

    Does this work for you?

    Please Login or Register  to view this content.
    Last edited by ByteMarks; 02-26-2024 at 10:53 AM.

  3. #3
    Registered User
    Join Date
    12-13-2023
    Location
    Melbourne
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Adding a name\word to a range of cells without deleting the data already in each cell.

    Hi ByteMarks, thanks so much for you post , unfortunately we use the file on excel for web to schedule around 15 machines & 40 people. As you would know, VBA macros don't work on excel online.

    I am a very average excel user. I have tried to automate the attached file to...
    • Show available people (row 98, names clear as names are added above)
    • Count number of names (row 2)
    • Look for duplicates (row 1)
    • Count number of machines working (row 3 )
    • Alphabetize people on leave (row 93)
    • Add people to leave on row 92
    • There are also a number of conditional formatting rules to highlight mistakes and current date


    I tried your macro and it works perfectly in a .xlsm, such a bummer macros don't work on excel for web.
    If you have any other suggestions or ways I could add names on mass to row 92 or any other ways to improve this file it would be really appreciated.
    FYI For privacy I have removed our clients company's names replaced with ZZ
    All the formulas work pretty well it only glitches if I drag names vertically.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,047

    Re: Adding a name\word to a range of cells without deleting the data already in each cell.

    Maybe something like this in Office Script

    PHP Code: 
    function main(workbookExcelScript.WorkbookTextToAddstring) {
      
    let sheet workbook.getActiveWorksheet();
      
    let SelRngworkbook.getSelectedRange();
      
    let NumRows SelRng.getRowCount();
      
    let NumCols SelRng.getColumnCount();
      
        for (
    let r=0NumRows;r++){
          for (
    let c=0cNumColsc++) {
            
    let v SelRng.getCell(rc).getValue() as string;
            
    v.trim()
            if (
    v.length == 0) {
              
    //blank cell
              
    SelRng.getCell(r,c).setValue(TextToAdd);
            } else {
            
    //populated cell
              
    if (v.includes(TextToAdd) == false) { //don't add if cell already contains it. May or may not be required.
                
    SelRng.getCell(r,c).setValue(" " TextToAdd)
              } 
            }    
          }
        }
      } 
    Last edited by ByteMarks; 02-28-2024 at 07:55 AM.

+ 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: 2
    Last Post: 09-16-2020, 01:06 PM
  2. [SOLVED] VBA - Shift data in range (row) left towards first cell WITHOUT deleting cells.
    By JJGF in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-14-2018, 12:54 AM
  3. Deleting a range using active cell and cells command
    By beasley101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-13-2015, 08:17 AM
  4. [SOLVED] Deleting units allocated in a range of cells based on the cell rank
    By LBala in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-07-2014, 12:36 AM
  5. Deleting a range of cells based on a deletion of a cell outside that range
    By Carlos90 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2013, 03:07 PM
  6. Replies: 9
    Last Post: 08-14-2013, 12:10 AM
  7. Adding rows to named range and deleting them
    By Djwill in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2012, 02:56 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