Pasting data to a dynamic range using VBA

CMDMA03

New Member
Joined
Sep 23, 2011
Messages
12
I am trying to paste a single cell value to a range that will vary according to row counts in two different columns. I'm pasting in column B so I want to use .Range("B" & BRowCount) as my starting value. I then want to paste the value down column B until I reach the last used row in column C (i.e., .Range("B" & CRowCount)). None of the paste range code that I am trying seems to work. Does anyone have suggesstions?

Code:
With CS
        BRowCount = CS.Range("B65536").End(xlUp).Row
        BRowCount = BRowCount + 1
        .Range("B" & BRowCount).PasteSpecial Paste:=xlPasteValues
        .Range("B" & BRowCount).Copy
        CRowCount = CS.Range("C65536").End(xlUp).Row
        '---->Paste Code Inserted Here
End With
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Does this fit your needs (untested)

Code:
CS.Select
     BRowCount = Cells(Rows.Count, 2).End(xlUp).Row
     CRowCount = Cells(Rows.Count, 3).End(xlUp).Row
     [C1].Offset(CRowCount).Value = [B1].Offset(BRowCount).Value
 
Upvote 0
Didn't work. I've also tried the code below with no luck. I've used code that has a dynamic end point before (e.g., .Range("B2:B" & BRowCount)), but have not ever needed something to have a dynamic begin and end point.


Code:
.Range("B" & BRowCount:"B" & CCowCount).PasteSpecial Paste:=xlPasteValues

Code:
rngStart = .Range("B" & BRowCount)
rngEnd = .Range("B" & CRowCount)
.Range(rngStart:rngEnd).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
OK, I need to get some clarification..

You're pasting a value in the first open cell in Column B and filling the rest of the column until Column C is empty?

If so...does this do it?

Code:
Dim rng As Range
BRowCount = Cells(Rows.Count, 2).End(xlUp).Offset(1).Row
CRowCount = Cells(Rows.Count, 3).End(xlUp).Row
    For Each rng In Range("B" & BRowCount & ":B" & CRowCount)
        rng.PasteSpecial xlPasteValues
    Next rng
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,524
Messages
6,131,176
Members
449,629
Latest member
Mjereza

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