Macro ask for user input and paste it into every nth row

Fiveshorter

New Member
Joined
Jul 14, 2017
Messages
18
Hi,

I have two columns of data :
[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]33[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]12

[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]44[/TD]
[/TR]
</tbody>[/TABLE]

What I would like to be able to do is ask the user how many in column 1, cells are the same (what is the trend) in this case it would be two as we have Two As, Two Bs. Then I would like to be able to prompt the user for two inputs ( as we entered two before this as this is the trend ), input the letter 'D' and the number "33.33". So the data will now look like this :
[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]23[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]33[/TD]
[TD]33.33[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]12[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]44[/TD]
[TD]33.33[/TD]
[/TR]
</tbody>[/TABLE]


Another example if I had the following table :
[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]22[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]34[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]13[/TD]
[/TR]
</tbody>[/TABLE]


The trend is 3 as we have 3 a's and 3 b's. Then we enter 3 pieces of information, input 1 =2.22, input 2 = 444.55, input 3 = 33.99999 and our table would look like this :
[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]22[/TD]
[TD]2.22[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]34[/TD]
[TD]444.55[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]4[/TD]
[TD]33.99999[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]23[/TD]
[TD]2.22[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]2[/TD]
[TD]444.55[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]13[/TD]
[TD]33.99999[/TD]
[/TR]
</tbody>[/TABLE]

If anyone could help to build a macro for this it would be greatly appreciated, hopefully I explained well enough!

Thanks!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
assuming you data starts in row 1,

Code:
Sub Do_it()
wr = -1

lr = Cells(Rows.Count, "A").End(xlUp).Row

x = Int(InputBox("What is the trend"))
If Not x > 0 Then Exit Sub
For t = 1 To x
     Data = InputBox("What is the data point #" & t)
For r = 1 To lr Step x
     Cells(wr + r + t, "B") = Data
Next r
Next t
End Sub

hth,

Ross
 
Upvote 0

Forum statistics

Threads
1,225,757
Messages
6,186,850
Members
453,379
Latest member
gabriellegonzalez

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top