Adding data to end of row based on A1 value

Royalty13

New Member
Joined
Nov 14, 2013
Messages
6
I'm working with a rather long list that I'm trying to add to the end of a spreadsheet. I know there are formula's out there that can go to the next empty cell in a row or a column, but I need a vba code that can go to the next empty cell in a row based on the first column's value.
For example:

Sample list:
[TABLE="width: 100"]
<tbody>[TR]
[TD]Dog[/TD]
[TD]Pitbull[/TD]
[/TR]
[TR]
[TD]Cat[/TD]
[TD]Sphynx[/TD]
[/TR]
[TR]
[TD]Dog[/TD]
[TD]Beagle[/TD]
[/TR]
[TR]
[TD]Bird[/TD]
[TD]Parrot[/TD]
[/TR]
</tbody>[/TABLE]

Sample spreadsheet:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Bird[/TD]
[TD]Toucan[/TD]
[TD]Owl[/TD]
[TD]Eagle[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Dog[/TD]
[TD]Rottweiler[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Cat[/TD]
[TD]Siamese[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Final result:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Bird[/TD]
[TD]Toucan[/TD]
[TD]Owl[/TD]
[TD]Eagle[/TD]
[TD]Parrot[/TD]
[/TR]
[TR]
[TD]Dog[/TD]
[TD]Rottweiler[/TD]
[TD]Pitbull[/TD]
[TD]Beagle[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Cat[/TD]
[TD]Siamese[/TD]
[TD]Sphynx[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Is there any easy way to do this?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
With "Sample data" in sheet "Data" and "Sample Spreadsheet" in sheet "Results
Actual data starting rows 2.
Try this for update on sheet "Results":-
Code:
[COLOR="Navy"]Sub[/COLOR] MG24Apr07
[COLOR="Navy"]Dim[/COLOR] RngR [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] RngD [COLOR="Navy"]As[/COLOR] Range, Q [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]With[/COLOR] Sheets("Results")
[COLOR="Navy"]Set[/COLOR] RngR = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] RngR
    Lst = Cells(Dn.Row, Columns.Count).End(xlToLeft).Column
    .Item(Dn.Value) = Array(Dn, Lst)
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]With[/COLOR] Sheets("Data")
    [COLOR="Navy"]Set[/COLOR] RngD = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] RngD
        [COLOR="Navy"]If[/COLOR] .exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
            Q = .Item(Dn.Value)
            Q(0).Offset(, Q(1)) = Dn.Offset(, 1).Value
            Q(1) = Q(1) + 1
            .Item(Dn.Value) = Q
        [COLOR="Navy"]End[/COLOR] If
  [COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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