How do I get this VBA to paste values?

NHagedorn

New Member
Joined
May 11, 2012
Messages
37
Office Version
  1. 365
Platform
  1. Windows
How do I adjust this VBA to paste values?


Sub CDRCombine()
Application.ScreenUpdating = False
Dim wsCDR As Worksheet
Dim LastRowWs As Long
Dim LastRowCDR As Long
Dim StartRowCDR As Long

Set wsCDR = ThisWorkbook.Worksheets("CDR")
LastRowCDR = wsCDR.Cells(wsCDR.Rows.Count, "A").End(xlUp).Row + 1
wsCDR.Range("A2:R" & LastRowCDR).Clear

For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Acct Setup" And ws.Name <> "Pres Setup" And ws.Name <> "Data" And ws.Name <> "Stuff" And ws.Name <> "Next Injection" And ws.Name <> "Pull Through" And ws.Name <> "CDR" And ws.Name <> "Acct-W-Syr-Prolia(spec)" And ws.Name <> "Pres-W-Syr-Prolia(spec)" Then
LastRowWs = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
StartRowCDR = wsCDR.Cells(wsCDR.Rows.Count, "A").End(xlUp).Row + 1 'first empty row

ws.Range("A2:R" & LastRowWs).Copy Destination:=wsCDR.Range("A" & StartRowCDR)
LastRowCDR = wsCDR.Cells(wsCDR.Rows.Count, "A").End(xlUp).Row

wsCDR.Range("E" & StartRowCDR & ":E" & LastRowCDR) = ws.Name
End If
Next
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try something like this:
Code:
Sub Sample()
wsCDR.Range("A" & StartRowCDR).Value = ws.Range("A2:R" & LastRowWs).Value
End Sub
 
Upvote 0
How about
Code:
wsCDR.Range("A" & StartRowCDR).Resize(LastRowWs - 1, 18).Value = Ws.Range("A2:R" & LastRowWs).Value
 
Last edited:
Upvote 0
Thank you for the quick response but I'm sorry.... I'm not sure where to insert it.
 
Upvote 0
Fluff .... replaced your code with the copy destination line.... works great! Thank you

Other code..... only posted 8 cells?
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Fluff,

Any idea how do I adjust the code further so that it posts in A3 rather than A2? I changed the -1 to -2 but that gave me the A3 but also an additional space between the pastings of the sheets.

Thank you
 
Upvote 0
Try adding this line
Code:
StartRowCDR = wsCDR.Cells(wsCDR.Rows.Count, "A").End(xlUp).Row + 1
[COLOR=#0000ff]If StartRowCDR = 2 Then StartRowCDR = 3[/COLOR]
wsCDR.Range("A" & StartRowCDR).Resize(LastRowWs - 1, 18).Value = ws.Range("A2:R" & LastRowWs).Value
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

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