Using vlookup to copypaste values to row using vba codes

HearMePlease

New Member
Joined
Jul 26, 2018
Messages
6
Hey Masters,

Good morning! Im a newbies in VBA and want to learn more about it to speed up my work.

I have this file which needs to be sorted everyday. Copy all the movements to each corresponding sites. Please see below the example.

Store No_ Amount Tendered 0106010901110112011701190120012301250126012701310161
0106 39,250.00
0106 18,400.00
0109 170,000.00
0111 1,680,200.00
0112 20,000.00
0117 5,000.00
0119 4,400.00
0120 3,950.00
0123 15,150.00
0125 13,650.00
0126 653,700.00
0127 16,500.00
0131 3,000.00
0161 2,000.00


<colgroup><col><col><col span="4"><col><col span="9"></colgroup><tbody>
</tbody>

Can you please help me copypaste values in each store number using VBA codes.

Thank you for your help.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Welcome to the MrExcel board!

There are many ways to approach most problems in Excel/VBA. Here is one method (assuming that I have interpreted correctly what result you want ;))

Code:
Sub AllocateToSite()
  Dim d As Object
  Dim c As Range
  
  Set d = CreateObject("Scripting.Dictionary")
  For Each c In Range("D1", Range("D1").End(xlToRight))
    d(c.Value) = c.Column
  Next c
  For Each c In Range("B2", Range("B2").End(xlDown))
    Cells(c.Row, d(c.Offset(, -1).Value)).Value = c.Value
  Next c
End Sub

My sheet after running the code.


Book1
ABCDEFGHIJKLMNOP
1Store No_Amount Tendered106109111112117119120123125126127131161
210639,250.0039250
310618,400.0018400
4109170,000.00170000
51111,680,200.001680200
611220,000.0020000
71175,000.005000
81194,400.004400
91203,950.003950
1012315,150.0015150
1112513,650.0013650
12126653,700.00653700
1312716,500.0016500
141313,000.003000
151612,000.002000
Allocate to site
 
Upvote 0
Thank you for your warm welcome!
Thank you Peter_SSs for sharing your knowledge to a newbies like me. This is the code that i really wanted.
It really works!
 
Upvote 0
Thank you for your warm welcome!
Thank you Peter_SSs for sharing your knowledge to a newbies like me. This is the code that i really wanted.
It really works!
You are very welcome. It is what the forum is for. :)
 
Upvote 0
Hi Peter_SSs,

Can i ask if we can add some codes so that the final report will look like this?

Store No_ Amount Tendered 0106010901110112011701190120012301250126012701310161
0106 39,250.00 39,250.00 170,000.00 1,680,200.00 20,000.00 5,000.00 4,400.00 3,950.00 15,150.00 13,650.00 653,700.00 16,500.00 3,000.00 2,000.00
0106 18,400.00 18,400.00
0109 170,000.00
0111 1,680,200.00
0112 20,000.00
0117 5,000.00
0119 4,400.00
0120 3,950.00
0123 15,150.00
0125 13,650.00
0126 653,700.00
0127 16,500.00
0131 3,000.00
0161 2,000.00

<colgroup><col><col><col><col span="4"><col><col><col><col span="2"><col><col span="3"></colgroup><tbody>
</tbody>


<colgroup><col><col><col><col span="4"><col><col><col><col span="2"><col><col span="3"></colgroup><tbody></tbody>



Thank you very much.

Regards,

HearMePlease
 
Upvote 0
Can i ask if we can add some codes so that the final report will look like this?
Sure, just add this blue text
Rich (BB code):
Cells(c.Row, d(c.Offset(, -1).Value)).End(xlUp).Offset(1).Value = c.Value
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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