VBA Adding Data to Columns From Above

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,180
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have data that comes off of an older program, like below is it possible to add in the school name and the teacher name (that is above the data) to the first row in the data like below?

Thanks in advance Stephen

Book1
ABCDEFG
1Lincoln-Rm: B223, Mrs. Y
2
3DateUser NameIDTest NameScore
4
53/25/2009xxxxxxx xxxxx299287177Reading - Grade 3 Marking Period 324
6
73/26/2009xxxxxxx xxxxx299287179Reading - Grade 3 Marking Period 348
8
93/27/2009xxxxxxx xxxxx299287181Reading - Grade 3 Marking Period 369
10
113/25/2009xxxxxxx xxxxx299287183Reading - Grade 3 Marking Period 355
12
133/25/2009xxxxxxx xxxxx299287185Reading - Grade 3 Marking Period 367
14
153/25/2009xxxxxxx xxxxx299287187Reading - Grade 3 Marking Period 348
16
173/25/2009xxxxxxx xxxxx299287189Reading - Grade 3 Marking Period 367
18
193/25/2009xxxxxxx xxxxx299287191Reading - Grade 3 Marking Period 314
20
213/25/2009xxxxxxx xxxxx299287193Reading - Grade 3 Marking Period 360
22
233/25/2009xxxxxxx xxxxx299287195Reading - Grade 3 Marking Period 331
24
253/25/2009xxxxxxx xxxxx299287197Reading - Grade 3 Marking Period 340
26
27
28
29Washington-Rm: 305, Mr X
30
31DateUser NameIDTest NameScore
32
333/25/2009xxxxxxx xxxxx299287198Reading - Grade 3 Marking Period 364
34
353/25/2009xxxxxxx xxxxx299287200Reading - Grade 3 Marking Period 364
36
373/25/2009xxxxxxx xxxxx299287202Reading - Grade 3 Marking Period 383
38
393/25/2009xxxxxxx xxxxx299287204Reading - Grade 3 Marking Period 362
Sheet1



to this



Book1
ABCDEFG
3DateUser NameIDTest NameScore
4
53/25/2009LincolnMrs. Yxxxxxxx xxxxx299287177Reading - Grade 3 Marking Period 324
6
73/26/2009xxxxxxx xxxxx299287179Reading - Grade 3 Marking Period 348
8
93/27/2009xxxxxxx xxxxx299287181Reading - Grade 3 Marking Period 369
10
113/25/2009xxxxxxx xxxxx299287183Reading - Grade 3 Marking Period 355
12
133/25/2009xxxxxxx xxxxx299287185Reading - Grade 3 Marking Period 367
14
153/25/2009xxxxxxx xxxxx299287187Reading - Grade 3 Marking Period 348
16
173/25/2009xxxxxxx xxxxx299287189Reading - Grade 3 Marking Period 367
18
193/25/2009xxxxxxx xxxxx299287191Reading - Grade 3 Marking Period 314
20
213/25/2009xxxxxxx xxxxx299287193Reading - Grade 3 Marking Period 360
22
233/25/2009xxxxxxx xxxxx299287195Reading - Grade 3 Marking Period 331
24
253/25/2009xxxxxxx xxxxx299287197Reading - Grade 3 Marking Period 340
26
27
28
29
30
31DateUser NameIDTest NameScore
32
333/25/2009WashingtonMr Xxxxxxxx xxxxx299287198Reading - Grade 3 Marking Period 364
34
353/25/2009xxxxxxx xxxxx299287200Reading - Grade 3 Marking Period 364
36
373/25/2009xxxxxxx xxxxx299287202Reading - Grade 3 Marking Period 383
38
393/25/2009xxxxxxx xxxxx299287204Reading - Grade 3 Marking Period 362
Sheet1
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this:-
NB:- Note the "Remark" in code.
Code:
[COLOR="Navy"]Sub[/COLOR] MG20May07
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Title [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Name [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Dn(, 2) <> "" [COLOR="Navy"]Then[/COLOR]
        Name = Split(Dn(, 2), "-")(0)
        Title = Split(Dn(, 2), ",")(1)
        Dn(, 2) = "" '[COLOR="Green"][B]Remove this line if you want to keep the original[/B][/COLOR]
        '[COLOR="Green"][B]Text in column "B"[/B][/COLOR]
    [COLOR="Navy"]ElseIf[/COLOR] IsDate(Dn) [COLOR="Navy"]Then[/COLOR]
        Dn(, 2) = Name: Dn(, 3) = Title
        Name = ""
        Title = ""
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thank you so Much Mick! Works great always admired your posts!
 
Upvote 0
Great timing, I have a similar related question. Assume that the data has been grouped similar to the poster's example where there is a value that I would like to copy to EVERY row within that group... the existing data looks like this:

A B C D E
1. BLUE
2. Ball
3. Pale
4. Book
5.
6. Number Blue=3
7.
8. RED
9. Sign
10. Cup
11. Door
12. Car
13. Poster
14.
15. Number Red=5

To now have my data have a 1-to-1 association and remove the grouping to perform pivots and other preferred ways to use the data, the final output would look like this essentially removing the grouping and label each row with the previous group value:

A B C D E
1. BLUE Ball
2. BLUE Pale
3. BLUE Book
4. RED Sign
5. RED Cup
6. RED Door
7. RED Car
8. RED Poster
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,839
Members
452,948
Latest member
UsmanAli786

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