Macro to copy parts of data from a row to specific location based on a value

galbatrox9

New Member
Joined
Aug 30, 2017
Messages
23
Hi Guys,

I have a raw excel sheet with rows of data that all have an account number in he first row. And i want to transfer those rows of data to a dedicated sheet per the account number. Now here is the thing. This i got with this code
Code:
If (InStr(1, Cells(i, 1).Value, "55711") > 0)  Then        Rows(i).Copy
        srow = ThisWorkbook.Sheets("DeltaMan").Range("A65536").End(xlUp).Row + 1
        ThisWorkbook.Sheets("DeltaMan").Cells(srow, 1).PasteSpecial (xlPasteValues)

But here comes the biggest challenge.

Raw sheet details:
jkCLt5u.jpg


I want the data to be copied to their respective sheets , but the row's data needs to be shuffled in this way

IWbZfSa.jpg




Can this be done? So the macro should do this :
-If a row that 55711 in Col. A , then copy data from column C (date) and paste in Column A of 'DeltaMan' sheet, etc etc.


Can someone please help me here.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Do the dedicated sheets per the account number already exist or do they have to be created?
 
Upvote 0
What do the values in Col A look like?
 
Upvote 0
Try:
Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim bottomA As Long
    bottomA = Range("A" & Rows.Count).End(xlUp).Row
    Dim AccNum As Range
    For Each AccNum In Range("A2:A" & bottomA)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) = AccNum.Offset(0, 2)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) = AccNum
        Sheets(CStr(AccNum)).Cells(Rows.Count, "C").End(xlUp).Offset(1, 0) = AccNum.Offset(0, 1)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "D").End(xlUp).Offset(1, 0) = AccNum.Offset(0, 4)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "E").End(xlUp).Offset(1, 0) = AccNum.Offset(0, 3)
    Next AccNum
    Application.ScreenUpdating = True
End Sub
I'm assuming that the sheet names are the account numbers but it looks like they may be named after the name. If they are named after the name, then the macro will have to be modified.
 
Last edited:
Upvote 0
Try:
Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim bottomA As Long
    bottomA = Range("A" & Rows.Count).End(xlUp).Row
    Dim AccNum As Range
    For Each AccNum In Range("A2:A" & bottomA)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) = AccNum.Offset(0, 2)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) = AccNum
        Sheets(CStr(AccNum)).Cells(Rows.Count, "C").End(xlUp).Offset(1, 0) = AccNum.Offset(0, 1)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "D").End(xlUp).Offset(1, 0) = AccNum.Offset(0, 4)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "E").End(xlUp).Offset(1, 0) = AccNum.Offset(0, 3)
    Next AccNum
    Application.ScreenUpdating = True
End Sub
I'm assuming that the sheet names are the account numbers.

It didnt work buddy.

Can a simple code be possible which works on the basis of me writing the account number in the code which will do to a sheet? since the account number will not be the same as the sheet name.
 
Upvote 0
Are the sheet names based on Name, Date, Value or Counterparty or are they totally different?
 
Last edited:
Upvote 0
The sheet names are based on nothing from the raw sheet. As the name given in the sheet is different from my sheet names.
(Below is an example of my sheet names)
557111 - DeltaMan
557118 - GalbaBax
883913 - StockBoy
 
Upvote 0
We have to have some way of linking the account number to the appropriate sheet. We can do this by you listing all 10 accounts with the associated sheet name. You have listed 3 of them. What are the other 7?
 
Upvote 0
We have to have some way of linking the account number to the appropriate sheet. We can do this by you listing all 10 accounts with the associated sheet name. You have listed 3 of them. What are the other 7?
Oh i thought if you could come up with a line of code, i would just copy and paste it for the other acc's.
Code:
[TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64"]557111-DeltaMan[/TD]
[/TR]
[TR]
[TD]557118-GalbaBax[/TD]
[/TR]
[TR]
[TD]883913-StockBoy[/TD]
[/TR]
[TR]
[TD]931585-RusselT[/TD]
[/TR]
[TR]
[TD]758474-4462Tral[/TD]
[/TR]
[TR]
[TD]114221-555Hotel[/TD]
[/TR]
[TR]
[TD]113251-BountyCap[/TD]
[/TR]
[TR]
[TD]114229-Dabur12[/TD]
[/TR]
[TR]
[TD]100005-ViteSam01[/TD]
[/TR]
[TR]
[TD]982742-Arouq2[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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