Excel Data Merging/ data Analysis

akpflow

New Member
Joined
Aug 2, 2016
Messages
9
Good day people. Thank you for your support so far...
I need to merge some data values from some spreadsheets to another..
Table A for Year 2013
Family IDCityStatePostal Code Amount

<tbody>
</tbody>

Table B for Year 2014
Family IDCityStatePostal Code Amount

<tbody>
</tbody>


Merged Table
Family IDCityState2013 Amount2014 Amount2015 Amount2016 Amount

<tbody>
</tbody>

Question 2:
How can I use excel to design a line graph to show amount vs time in a graph?



Thank you
 

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)
I created five sheets named: Table A, Table B, Table C, Table D, Merged using the years you posted. I tried to have excel do the line graph automatically for you, but I think I have a bug in excel 2013 or windows update. Nothing I tried would create the line graph using vba. Vba will create the chart, and place it, but it will not do the xlLineMarkers. I have to manually click on the data points and change it. Hopefully someone on here will be able to help with that part of it. I have included what the macro recorder did in case it may help you figure something out. I will post screenshots of how I setup each sheet and show you the merged sheet after macro runs.

Excel Workbook
ABCDEFG
1Family IdCityStatePostal CodeAmountYear
2SmithAnywhereGa12345$5.002013
3SmythAnywhereGa12345$3.002013
4SmithAnywhereGa12345$1.002013
5SmythAnywhereGa12345$12.002013
6SmithAnywhereGa12345$7.002013
7
Table A


Excel Workbook
ABCDEFG
1Family IdCityStatePostal CodeAmountYear
2SmithAnywhereSc12345$7.002014
3SmythAnywhereSc12345$6.002014
4SmithAnywhereSc12345$9.002014
5SmythAnywhereSc12345$4.002014
6SmithAnywhereSc12345$5.002014
7
Table B


Excel Workbook
ABCDEFG
1Family IdCityStatePostal CodeAmountYear
2SmithAnywhereKy12345$9.002015
3SmythAnywhereKy12345$7.002015
4SmithAnywhereKy12345$8.002015
5SmythAnywhereKy12345$12.002015
6SmithAnywhereKy12345$5.002015
7
Table C


Excel Workbook
ABCDEFG
1Family IdCityStatePostal CodeAmountYear
2SmithAnywhereMd12345$15.002016
3SmythAnywhereMd12345$10.002016
4SmithAnywhereMd12345$12.002016
5SmythAnywhereMd12345$3.002016
6SmithAnywhereMd12345$9.002016
7
Table D


Excel Workbook
ABCDEFG
1Family IdCityStateYearAmount
2
3
Merged


After code runs:

Excel Workbook
ABCDEFGHIJ
1Family IdCityStateYearAmountYearYearAmount
2SmithAnywhereGa2013$5.0020132013$5.00
3SmythAnywhereGa2013$3.002014$3.00
4SmithAnywhereGa2013$1.002015$1.00
5SmythAnywhereGa2013$12.002016$12.00
6SmithAnywhereGa2013$7.00$7.00
7SmithAnywhereSc2014$7.002014$7.00
8SmythAnywhereSc2014$6.00$6.00
9SmithAnywhereSc2014$9.00$9.00
10SmythAnywhereSc2014$4.00$4.00
11SmithAnywhereSc2014$5.00$5.00
12SmithAnywhereKy2015$9.002015$9.00
13SmythAnywhereKy2015$7.00$7.00
14SmithAnywhereKy2015$8.00$8.00
15SmythAnywhereKy2015$12.00$12.00
16SmithAnywhereKy2015$5.00$5.00
17SmithAnywhereMd2016$15.002016$15.00
18SmythAnywhereMd2016$10.00$10.00
19SmithAnywhereMd2016$12.00$12.00
20SmythAnywhereMd2016$3.00$3.00
21SmithAnywhereMd2016$9.00$9.00
22
Merged


Code:
Sub Merge_and_Chart()
Application.ScreenUpdating = False
Dim i As Long, j As Long, mylastrow As Long
Dim rng1 As Range, rng2 As Range, rng3 As Range, rng4 As Range, rng5 As Range
Dim myval As String, lastcolumn As Long
Dim add1 As Long, add2 As Long
Dim xrow As Long, lastrow As Long, rng As Range

For i = 1 To Worksheets.Count - 1
Sheets(i).Activate
With Sheets(i)
    Set rng1 = Sheets(i).Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
    Set rng2 = Sheets(i).Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row)
    Set rng3 = Sheets(i).Range("C2:C" & Cells(Rows.Count, 3).End(xlUp).Row)
    Set rng5 = Sheets(i).Range("E2:E" & Cells(Rows.Count, 5).End(xlUp).Row)
    Set rng4 = Sheets(i).Range("F2:F" & Cells(Rows.Count, 6).End(xlUp).Row)
End With

Sheets("Merged").Activate
    
    Sheets("Merged").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Resize(rng1.Rows.Count, rng1.Columns.Count).Cells.Value = rng1.Cells.Value
    Sheets("Merged").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Resize(rng2.Rows.Count, rng2.Columns.Count).Cells.Value = rng2.Cells.Value
    Sheets("Merged").Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Resize(rng3.Rows.Count, rng3.Columns.Count).Cells.Value = rng3.Cells.Value
    Sheets("Merged").Cells(Rows.Count, 4).End(xlUp).Offset(1, 0).Resize(rng4.Rows.Count, rng4.Columns.Count).Cells.Value = rng4.Cells.Value
    Sheets("Merged").Cells(Rows.Count, 5).End(xlUp).Offset(1, 0).Resize(rng5.Rows.Count, rng5.Columns.Count).Cells.Value = rng5.Cells.Value
    
Next

Range("D:D").Copy Range("G1")
Range("G2").Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.RemoveDuplicates Columns:=Array(1), Header:=xlNo
Selection.Sort key1:=ActiveCell, order1:=xlAscending
Range("H1").Value = "Year"
Range("I1").Value = "Amount"
Range("F1").Activate

mylastrow = Cells(Rows.Count, 7).End(xlUp).Row

For j = 2 To mylastrow

myval = Cells(j, 7).Value
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = _
    Cells.Find(What:="*", After:=Range("A1"), SearchOrder:=xlByColumns, _
        SearchDirection:=xlPrevious).Offset(0, -4).Column
add1 = Columns(4).Find(What:=myval, LookIn:=xlValues, LookAt:=xlWhole).Row
xrow = add1

Do

If Cells(xrow + 1, 4).Value <> myval Then
    add2 = xrow
    Exit Do
Else
    xrow = xrow + 1
End If

Loop Until xrow = lastrow + 1

Range(Cells(add1, lastcolumn), Cells(add2, lastcolumn)).Copy Cells(Rows.Count, 9).End(xlUp).Offset(1, 0)
Range(Cells(add1, 4), Cells(add1, 4)).Copy Cells(add1, 8)

Next

Range("H1:I" & Cells(Rows.Count, 9).End(xlUp).Row).Select
Set rng = Selection
    ActiveSheet.Shapes.AddChart2(332, xlLineMarkers).Select
    ActiveChart.SetSourceData Source:=rng
    ActiveSheet.Shapes("Chart 1").IncrementLeft 38.25
    ActiveSheet.Shapes("Chart 1").IncrementTop -166.5
    ActiveSheet.Shapes("Chart 1").ScaleWidth 1.1979166667, msoFalse, _
        msoScaleFromTopLeft

Range("F1").Select

Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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