Copy cell to undetermined range

Crabbit

New Member
Joined
Nov 9, 2005
Messages
4
Need some help please!!!
I am writing a macro whereby I need a cell to be copied down a column. However I can not specify the amount of rows it needs to be copied to as this will change everytime the macro is run.
In the next column is the start of a database, where records are constantly added or deleted from and I need the "problem" cell to be copied to all records, this will be the first column of the database.

Code Company
12345 AAA
bbb
ccc
ddd
eee
Example: Need 12345 to be copied to all cells in Code column. The amound of cells copied depends on the amount of cells in Company column.

Hope this makes sense. ANy help would be really appreciated.
Thanks

PS I am presently recording the macro as am not brilliant at code but any help would be appreciated
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hello and welcome to the board,

Care to post the code you have created already.

It sound like you want autofill, something like this perhaps

Code:
    Range("A1").AutoFill Destination:=Range("A1:A" & Range("B65536").End(xlUp).Row)
(xlUp).Row)

Change cell refs as required.
 
Upvote 0
Oops...

Your solution worked brilliantly until I copied the database again, above the existing cells leaving an empty row between the two sets of cells. The copied cells are now(when the macro is run again) pasted all the way down instead of just to the new Range. I was hoping that the copied cells would would stop copy when it hit an empty row.
Example

Column A Column B
1237 aaaaa
bbbbb
ccccc


1238 aaaaa
1238 bbbb
1238 ccccc

My macro needs cell 1237 to be copied down to cccc in first group of cells only as second group already has info needed.

Hope this makes sense and any help would be appreciated.
Thanks
Clara
 
Upvote 0
Hello,

Like this perhaps?

Code:
Sub COPY_DOWN()
For MY_ROWS = Range("B65536").End(xlUp).Row To 1 Step -1
    If Range("A" & MY_ROWS).Value <> "" Then
          Range("A" & MY_ROWS).AutoFill Destination:=Range("A" & MY_ROWS & ":A" & _
            Range("B" & MY_ROWS).End(xlDown).Row)
    End If
Next MY_ROWS
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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