Associate values from columns

MegaMan

New Member
Joined
Jun 25, 2017
Messages
2
Hello,

below I have posted an excerpt of my table. I would like to assign only the first value of Column B to the Column A value. For example, my new table should have in Column A the value P01 and in Column B the value of 100. Thereafter, P02 and 1200, then U01 and 2000, then U02 and 1500, and finally R01 and 400.
Please also consider the case of P02: As you can see from the table, the first numerical value in Column B is in the second row and not the first row. Is that a Problem?

Is there a quick way (macro?) to solve this?

Thanks so much.


Column A
Column B
P01
100
200
300
P02
1200
1400
1600
U01
2000
2200
U02
1500
2500
R01
400
500

<tbody>
</tbody>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
P01100
200
300
P02<<<<blank
1200
1400
1600
U012000
2200
U021500
2500
R01400
500
this macro does it
Dim mycol1(20), mycol2(20)
For j = 1 To 20
If Cells(j, 1) <> "" Then GoTo 100 Else GoTo 900
100 For k = j To 20
If Cells(k, 2) <> "" Then GoTo 300 Else GoTo 400
300 Sum = Sum + 1
mycol1(Sum) = Cells(j, 1)
mycol2(Sum) = Cells(k, 2)
GoTo 900
400 Next k
900 Next j
For z = 30 To 29 + Sum
tot = tot + 1
Cells(z, 1) = mycol1(tot)
P01100 Cells(z, 2) = mycol2(tot)
P021200 Next z
U012000End Sub
U021500
R01400

<colgroup><col><col><col span="10"></colgroup><tbody>
</tbody>
 
Upvote 0
Thanks so far.

Visual Basic shows: "Compile error: Invalid outside procedure"

What should I do?


P01
100
200
300
P02
<<<<blank< p=""></blank<>
1200
1400
1600
U01
2000
2200
U02
1500
2500
R01
400
500
this macro does it
Dim mycol1(20), mycol2(20)
For j = 1 To 20
If Cells(j, 1) <> "" Then GoTo 100 Else GoTo 900
100 For k = j To 20
If Cells(k, 2) <> "" Then GoTo 300 Else GoTo 400
300 Sum = Sum + 1
mycol1(Sum) = Cells(j, 1)
mycol2(Sum) = Cells(k, 2)
GoTo 900
400 Next k
900 Next j
For z = 30 To 29 + Sum
tot = tot + 1
Cells(z, 1) = mycol1(tot)
P01
100
Cells(z, 2) = mycol2(tot)
P02
1200
Next z
U01
2000
End Sub
U02
1500
R01
400

<tbody>
</tbody>
 
Upvote 0
Welcome to the forum.

Please take a minute to read the forum rules, especially the one about cross-posting, and follow them. Thanks! :)
 
Upvote 0
if your data is in cols A and B I do not know - the macro runs normally for me...

copy your macro and paste it here in the reply box so we check for typos etc
 
Upvote 0
You're missing the declaration line for the procedure - you have an End Sub line but no starting Sub... line.
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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