+ Reply to Thread
Results 1 to 14 of 14

Entering a value in one cell single or multiple times based on data present in another cel

  1. #1
    Registered User
    Join Date
    02-22-2022
    Location
    India
    MS-Off Ver
    2019
    Posts
    7

    Entering a value in one cell single or multiple times based on data present in another cel

    Hello,

    I need help in entering a value in one cell single or multiple times based on data present in another cell separated by a line break.
    For Example :

    In the column - MPI ID-Type
    I need to input the value '99020101' five times as there are five data values (separated by line break) in column - MPI ID.
    Same needed for second row i.e.
    I need to input the value '99020101' seven times as there are seven data values..

    Screensho.png

    Can anyone help me to achieve this as manually entering the data accordingly to another cell is very time consuming task.

    Thanks & Best regards.

    Attachment 803084
    Attached Files Attached Files
    Last edited by utking; 10-31-2022 at 11:27 PM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Entering a value in one cell single or multiple times based on data present in another


    Hello,

    according to your attachment you just need this single VBA codeline : Range("A2", [B1].End(xlDown)(1, 0)).FillDown ...

  3. #3
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Entering a value in one cell single or multiple times based on data present in another

    Hi utking,
    No, no, no, no!... What is shown in the image has nothing to do with what is in your workbook. Specifically:
    • In your picture, you has merged cells in column A.
    • While in your workbook, column A does NOT have merged cells.


    Could you clarify this?

  4. #4
    Registered User
    Join Date
    02-22-2022
    Location
    India
    MS-Off Ver
    2019
    Posts
    7

    Re: Entering a value in one cell single or multiple times based on data present in another

    Thanks for pointing out this,

    I don't know what the issue is but when I am opening the same file in google sheets it's been showing two columns but in MS-excel its showing merged.

    I had check this and rectified the same.
    Last edited by utking; 10-31-2022 at 11:26 PM.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    According to your new attachment an only Excel / VBA basics demonstration as a beginner starter :

    PHP Code: 
    Sub Demo1()
            
    Dim VR&, C%
        
    With Range("B2", [B1].End(xlDown))
            
    = .Value
        
    For 1 To .Rows.Count
            V
    (R1) = Split(V(R1), vbLf)
            For 
    0 To UBound(V(R1)) + (V(R1)(UBound(V(R1))) = ""):  V(R1)(C) = "99020101":  Next
            V
    (R1) = Join(V(R1), vbLf)
        
    Next
           
    .Columns(0).Font.Size = .Cells(10).Font.Size
           
    .Columns(0) = V
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 11-01-2022 at 01:05 PM. Reason: optimization ...

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,023

    Re: Entering a value in one cell single or multiple times based on data present in another

    @ MarcL

    I notice that on all your posted code you always have undeclared variables...Just out of interest...Do you not make use of the Option Explicit - Force declaration setting...
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Entering a value in one cell single or multiple times based on data present in another


    As when I code I merely do not need to declare any.
    I just forgot here the variable C, my previous post is now updated, thanks ...

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,023

    Re: Entering a value in one cell single or multiple times based on data present in another

    Was just wondering as it would error when you test your code...

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Entering a value in one cell single or multiple times based on data present in another


    No as this kind of code well works with only Variant variables like VBScript ...

    So I test first my code then just before posting I add the Dim codeline 'cause of 'haters'
    but here as I was on phone I just forgot the variable C.

  10. #10
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Entering a value in one cell single or multiple times based on data present in another

    Hello utking. The macro that I show you below:

    Please Login or Register  to view this content.
    solves the following:


    Cases:
    • One, two, several or no data in column A.
    • MPI ID-Type changes in column A
    Attached Images Attached Images

  11. #11
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,023

    Re: Entering a value in one cell single or multiple times based on data present in another

    Please Login or Register  to view this content.

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Try this ...


    According to the attachment a variation of my previous demonstration for starters :

    PHP Code: 
    Sub Demo1v()
          Const 
    "99020101"vbLf C
            Dim V
    R&
        
    With Range("B2", [B1].End(xlDown))
            
    = .Value
        
    For 1 To .Rows.Count
            V
    (R1) = Application.Rept(SLen(V(R1)) - Len(Replace(V(R1), vbLf"")) + (Right(V(R1), 1) = vbLf))
        
    Next
           
    .Columns(0).Font.Size = .Cells(10).Font.Size
           
    .Columns(0) = V
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 11-01-2022 at 01:20 PM. Reason: little tweak ...

  13. #13
    Registered User
    Join Date
    02-22-2022
    Location
    India
    MS-Off Ver
    2019
    Posts
    7

    Re: Try this !

    Quote Originally Posted by Marc L View Post

    According to your new attachment an only Excel / VBA basics demonstration as a beginner starter :

    PHP Code: 
    Sub Demo1()
            
    Dim VR&, C%
        
    With Range("B2", [B1].End(xlDown))
            
    = .Value
        
    For 1 To .Rows.Count
            V
    (R1) = Split(V(R1), vbLf)
            For 
    0 To UBound(V(R1)) + (V(R1)(UBound(V(R1))) = ""):  V(R1)(C) = "99020101":  Next
            V
    (R1) = Join(V(R1), vbLf)
        
    Next
           
    .Columns(0).Font.Size = .Cells(10).Font.Size
           
    .Columns(0) = V
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    The Code worked like a charm.
    You are awesome. Thanks for the help sir.

    Mods, Please close this thread.

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Entering a value in one cell single or multiple times based on data present in another


    Thanks for the rep' !

    You should better use my more direct post #12 variation code ...

+ 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. Entering delimited data in a single cell
    By Lanzaman in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-13-2018, 11:36 AM
  2. [SOLVED] Count number times same value is present in a single Row of a larger range.
    By ManinOZ in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 08-25-2015, 05:42 AM
  3. Replies: 5
    Last Post: 02-09-2014, 11:04 PM
  4. [SOLVED] Auto Hiding rows based on range/data present or not present.
    By raze in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 02-10-2013, 11:27 AM
  5. Display data from multiple cell in a single cell, based on criteria
    By Mothman in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-08-2012, 07:24 AM
  6. Entering Multiple Formulas for a single cell
    By modest_16081982 in forum Excel General
    Replies: 2
    Last Post: 07-30-2007, 09:58 PM
  7. [SOLVED] Multiple dates, times, or formulas in a single cell
    By PM-S in forum Excel General
    Replies: 2
    Last Post: 01-12-2006, 12:25 AM

Tags for this Thread

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