VBA to Copy Cells with specific text and paste in adjacent/subsequent column if text is found

SarahD139142

New Member
Joined
Apr 8, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I am beginner to VBA, so pardon my ignorance :)... I have Department Data in Column B with Department Names as headers, all in the same column. I am trying to create a macro to copy the department name and paste into Column A when the data is found in Column B. I haven't been able to find any thread on any site that addresses this. I included an image of my data and highlighted the cells I am concerned about. I would like to take the blue cell and paste it in the orange cells, and continue this for 20,000 rows. However, there is variability in the number of orange rows. Any help is appreciated!!! or is this even possible, haha.

RevMan.xlsm
ABCDEF
12Department: EG 4 EAST-211125
13Charge Review Details by Rule
14Charge Line CountSession CountAmountRatio to Pre AR
1544 - PROCEDURE PRICE CANNOT BE EMPTY1100.00%
1645 - PROCEDURE MUST BE IN AT LEAST ONE OF THE FEE SCHEDULES SEARCHED1100.00%
17260001 - WARNING POS NEEDED FOR INPATIENT AND OUTPATIENT CHARGES1100.00%
18607888 - CHOA PB CORRECT DEP CHARGE1100.00%
19609863 - CHOA PB POS MUST HAVE LOCATION TYPE OF POS1100.00%
20
21Department: EG 5 EAST-211130
22Charge Review Details by Rule
23Charge Line CountSession CountAmountRatio to Pre AR
24260001 - WARNING POS NEEDED FOR INPATIENT AND OUTPATIENT CHARGES1100.00%
25607888 - CHOA PB CORRECT DEP CHARGE1100.00%
26609863 - CHOA PB POS MUST HAVE LOCATION TYPE OF POS1100.00%
Sheet4
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi & welcome to MrExcel.
Will you always have "Charge Review Details by Rule" in the row below the department, then a blank row & another blank row between the data & the next department?
 
Upvote 0
Yes, I will always want to copy the Department above "Charge Review Details by Rule", there will always be a blank row below "Charge Details by Rule", and then I will want to paste the Department in the column to the left of the cells (rules) below the blank row. It will always follow this same outline, but the variable is the number of rules/number of cells I need to paste the Department to. Thank you!!
 
Upvote 0
Ok, how about
VBA Code:
Sub SarahD()
   Dim Rng As Range
      
   For Each Rng In Range("C2", Range("C" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
      Rng.Offset(1, -2).Resize(Rng.Count - 1).Value = Rng.Offset(-2, -1).Resize(1).Value
   Next Rng
End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,024
Members
448,543
Latest member
MartinLarkin

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