0
votes

If I work in my spreadsheed, without using any vba-code, I could select a single cell, copy, then select a bunch of cells, and paste. The result would be that all the target cells are filled with whatever value was in the source cell.

How would I do this in vba-code?

You would think the following would work because it mimics the behavior described above, but it doesn't. It will fill the top cell of the target range with the value and leave the rest of the cells empty.

    Range("A1").Select
    Selection.Copy
    Range("B1:B12").Select
    ActiveSheet.Paste
1
It works for me. but you can use Range("A1").Copy Range("B1:B12") as one line.Scott Craner
I am baffled. Tried again with a fresh worksheet and it works like it should. The problem has to be something else then. Have to check my code again...vanao veneri
Sorry, my bad. The mistake was actually somewhere else in my code and I fixed it.vanao veneri

1 Answers

4
votes

You don't need to use copy & paste in VBA, you can set values on ranges, like so:

Range("B1:B12").Value = Range("A1").Value