rearranging data from one workbook to another

lcastanheiro

New Member
Joined
Feb 21, 2019
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I'm hoping someone can help me.

I have a worksheet where I record expenses (worksheet A) as they happen, then i need to submit the report that arranges the data in another format. How do I automatically transfer the amounts under the right category into worksheet B?

Thank your for your help.
 

Attachments

  • worksheet A.jpg
    worksheet A.jpg
    52.8 KB · Views: 7
  • Worksheet B.jpg
    Worksheet B.jpg
    67.5 KB · Views: 7

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Change references like sheet names etc. as required.
Can't find any reference for Cash/Card.
It assumes that Sheet2 has the proper header values in row 1.

Code:
Sub Maybe()
Option Explicit
Option Compare Text    '<----- Use this because capitalizing is not consistent in your examples.
Dim dataArr, i As Long, sh1 As Worksheet, sh2 As Worksheet, j As Long
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")
dataArr = sh1.Range("A1:E" & sh1.Cells(sh1.Rows.Count, 1).End(xlUp).Row).Value
j = 2
    For i = 2 To UBound(dataArr)
        sh2.Cells(j, sh2.Rows(1).Find(dataArr(1, 1)).Column).Value = dataArr(i, 1)
        sh2.Cells(j, sh2.Rows(1).Find(dataArr(1, 2)).Column).Value = dataArr(i, 2)
        sh2.Cells(j, sh2.Rows(1).Find(dataArr(i, 3)).Column).Value = dataArr(i, 5)
        j = j + 1
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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