Adding in Information in the middle and end of the string

RaydenUK

Board Regular
Joined
Mar 25, 2014
Messages
74
I have a column labeled with patient ID's and I need to add in a few quality control checkpoints. For example:

Column A
12134
12355
24345
13523
12312
14321

I would like to add into the data a DOA2 in the center and a DOA3 at the end to look like this:

Column A
12134
12355
24345
DOA2
13523
12312
14321
DOA3

What code would allow me to do this?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Assuming the IDs begin in cell A2:
Code:
Sub CenterAndEnd()
'Assume IDs start in A2
Dim lR As Long
lR = Range("A" & Rows.Count).End(xlUp).Row
Range("A" & lR + 1).Value = "DOA3"
With Range("A" & Int(lR / 2) + 2)
    .Insert shift:=xlDown
    .Offset(-1, 0).Value = "DOA2"
End With
End Sub
 
Upvote 0
Try this macro

Code:
Option Explicit


Sub AddControl()
Dim lr As Long
Dim x As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
x = lr / 2


Range("A" & x) = "DOA2"
Range("A" & lr + 1) = "DOA3"


End Sub
 
Upvote 0
Wow thanks guys. I didn't think of it before but how about it there is respective data in column B that needs to stay with column A.
 
Upvote 0
Wow thanks guys. I didn't think of it before but how about it there is respective data in column B that needs to stay with column A.

Change this line:


.Insert shift:=xlDown

To this:

.EntireRow.Insert
</pre>
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,839
Members
449,193
Latest member
MikeVol

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