VBA copying list not always in the same order

Mand13

New Member
Joined
Feb 28, 2014
Messages
11
Hi,

The VBA code I have is working fine.... until.... the codes do not fall in the cell that are stipulated in the code! I know what I need it to do but have failed several times to create the macro that will do it without a debug error. I am at my wits end now, as VBA coding does not come naturally to me :confused:

I have entered the code I have currently:
Sub Sub_10978070()
'
' Sub_10978070 Macro
'
'
Sheets("Info").Select
Columns("A:A").Select
Selection.Find(What:="10978070", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range("A9:C9").Select
Selection.Copy
Sheets("Weekly Totals").Select
Range("G19").Select
ActiveSheet.Paste
Sheets("Info").Select
Application.CutCopyMode = False
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 13434879
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub

There are a number of codes (currently with its own little macro!), which are always a list in Column A (though not always in the same order)

18098094 - Paste in cell D12
18067779 - Paste in cell A12
15377808 - Paste in cell A2
15387808 - Paste in cell D2
15127751 - Paste in cell J12
etc

I have to copy each code and place in a specific cell in the worksheet (Weekly Totals).

Any expertise would be much appreciated.

Thanks
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Please explain in words what your attempting to do.

Just explain in detail and tell us what your wanting not how you want it done.

The only thing you have said so far is:

I have to copy each code and place in a specific cell in the worksheet (Weekly Totals).

Copy what code and where is this code and paste it where?

Give sheet names column numbers and all details we may need.
 
Upvote 0
Create another sheet called "Data" and put those 8 digit numbers in col A and where they need to be pasted in col B e.g.

col a col B
18098094 D12

then try the below macro

Code:
Sub Copy_Paste()
Dim rng as Range, lr As long, ws as Worksheet, f as Range
set ws = ThisWorkbook.Sheets("Data")
Let lr = ws.Range("A" & Rows.count).end(xlup).row
For each rng in ws.Range("A1:A" & lr) ' A2 if you want headers
Set f = Sheets("Info").Columns("A:A").Find(What:=rng.Value)
If f Is Nothing then GoTo nextrng
f.copy sheets("Weekly Totals").Range(rng.Offset(0,1).Value)
nextrng:
Next rng
End sub
 
Upvote 0
Sorry .... here goes my explanation..

I have a workbook with two worksheets
1. Info
2. Weekly Totals

In the info sheet there is a list of codes (between 15 - 20 codes) with descriptions and values
Column A Column B Column C
15127751 Material 1 435000
15387808 Material 2 160000
15387801 Material 3 8000


In the Weekly total sheets there are boxes where certain codes have to be pasted (and it totals those values)
Material 1538
15387808
Material 1
435,000.00
15387801
Material 3
8000
Total
443,000.00

<tbody>
</tbody>

As you can see there can be more than one code in the box.

Currently I have a macro for each code
And a macro to "Run them all"

But the codes are not always the same order so,
Range("A9:C9").Select
Selection.Copy

Can copy the wrong material if it is no longer situated in that cell.

I need the macro to find the product in Column A and copy the A - C row of that product.

Hope this helps.....

Thanks

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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