Help with Paste Special Vba

theteerex

Board Regular
Joined
Mar 2, 2018
Messages
102
I am wondering why the syntax is wrong here:

Code:
Sub FindProj() 'Finds project name in Historical Worksheet and pastes it in Data Worksheet
Dim Lastrow As Long
Dim Newproj As Long
Dim Master As Range
Dim Masterrow As Long


Masterrow = Worksheets("Data").Range("Master").Rows.Count
Lastrow = Sheets("Historical").Cells(Rows.Count, "B").End(xlUp).Row
Newproj = Sheets("Data").Cells(Rows.Count, "C").End(xlUp).Row
Sheets("Historical").Cells(Lastrow, "B").Copy Sheets("Data").Cells(Newproj - Masterrow + 1, "C")[COLOR=#ff0000].PasteSpecial xlFormats[/COLOR]


End Sub

Code works fine without it but I would also like to keep formatting so user can follow data easily.
Help please.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I was responding to your message. Tried the modified code that you posted.
I just realized that you were trying to do two operations within one line of code (you can't do that). Try replacing this line of code...
Code:
[table="width: 500"]
[tr]
	[td]Sheets("Historical").Cells(Lastrow, "B").Copy Sheets("Data").Cells(Newproj - Masterrow + 1, "C").PasteSpecial xlFormats[/td]
[/tr]
[/table]
with these two lines of code...
Code:
[table="width: 500"]
[tr]
	[td]Sheets("Historical").Cells(LastRow, "B").Copy
Sheets("Data").Cells(Newproj - Masterrow + 1, "C").PasteSpecial xlFormats[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
I just realized that you were trying to do two operations within one line of code (you can't do that). Try replacing this line of code...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sheets("Historical").Cells(Lastrow, "B").Copy Sheets("Data").Cells(Newproj - Masterrow + 1, "C").PasteSpecial xlFormats[/TD]
[/TR]
</tbody>[/TABLE]
with these two lines of code...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sheets("Historical").Cells(LastRow, "B").Copy
Sheets("Data").Cells(Newproj - Masterrow + 1, "C").PasteSpecial xlFormats[/TD]
[/TR]
</tbody>[/TABLE]
Hi Rick, your code makes it so the cell is selected but not pasted. Is something missing at the end? Should the PasteSpecial be at the beginning maybe?
 
Upvote 0
I just realized that you were trying to do two operations within one line of code (you can't do that). Try replacing this line of code...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sheets("Historical").Cells(Lastrow, "B").Copy Sheets("Data").Cells(Newproj - Masterrow + 1, "C").PasteSpecial xlFormats[/TD]
[/TR]
</tbody>[/TABLE]
with these two lines of code...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sheets("Historical").Cells(LastRow, "B").Copy
Sheets("Data").Cells(Newproj - Masterrow + 1, "C").PasteSpecial xlFormats[/TD]
[/TR]
</tbody>[/TABLE]

Your code worked with a modification. I added an underscore after copy so the two lines were linked.
 
Last edited:
Upvote 0
This code is now pasting twice. Is there something I am doing wrong?
I tried modifying it based on the feedback I just received.
Code:
Sub AddProj() 'Adds new template to Data Worksheet


Sheet1.Range("Master").Copy
Sheet1.Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlFormats
FindProj


End Sub
 
Upvote 0
This code is now pasting twice. Is there something I am doing wrong?
I tried modifying it based on the feedback I just received.
Code:
Sub AddProj() 'Adds new template to Data Worksheet

Sheet1.Range("Master").Copy
Sheet1.Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlFormats
[B][COLOR="#FF0000"]FindProj[/COLOR][/B]

End Sub
Does FindProj call AddProj by any chance?
 
Upvote 0
Does FindProj call AddProj by any chance?
FindProj does not call AddProj.
AddProj copies a range and then calls FindProj which pastes a value in the first cell of that range.

Initially, I was thinking about it wrong and just realized that I wanted the range to have the same formatting.
FindProj simply pastes in a value.

So I tried what you said earlier and the code just doesn't work properly.
 
Upvote 0

Forum statistics

Threads
1,217,404
Messages
6,136,416
Members
450,010
Latest member
Doritto305

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