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..
According to your new attachment an only Excel / VBA basics demonstration as a beginner starter :
PHP Code:
Sub Demo1()
Dim V, R&, C%
With Range("B2", [B1].End(xlDown))
V = .Value
For R = 1 To .Rows.Count
V(R, 1) = Split(V(R, 1), vbLf)
For C = 0 To UBound(V(R, 1)) + (V(R, 1)(UBound(V(R, 1))) = ""): V(R, 1)(C) = "99020101": Next
V(R, 1) = Join(V(R, 1), vbLf)
Next
.Columns(0).Font.Size = .Cells(1, 0).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 ...
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!!!
According to the attachment a variation of my previous demonstration for starters :
PHP Code:
Sub Demo1v()
Const C = "99020101", S = vbLf & C
Dim V, R&
With Range("B2", [B1].End(xlDown))
V = .Value
For R = 1 To .Rows.Count
V(R, 1) = C & Application.Rept(S, Len(V(R, 1)) - Len(Replace(V(R, 1), vbLf, "")) + (Right(V(R, 1), 1) = vbLf))
Next
.Columns(0).Font.Size = .Cells(1, 0).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 ...
According to your new attachment an only Excel / VBA basics demonstration as a beginner starter :
PHP Code:
Sub Demo1()
Dim V, R&, C%
With Range("B2", [B1].End(xlDown))
V = .Value
For R = 1 To .Rows.Count
V(R, 1) = Split(V(R, 1), vbLf)
For C = 0 To UBound(V(R, 1)) + (V(R, 1)(UBound(V(R, 1))) = ""): V(R, 1)(C) = "99020101": Next
V(R, 1) = Join(V(R, 1), vbLf)
Next
.Columns(0).Font.Size = .Cells(1, 0).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.
Bookmarks