copy and past if a cell value is yes

bthyaabd

New Member
Joined
Nov 16, 2022
Messages
5
Office Version
  1. 2007
Platform
  1. Windows
hello there,

i am trying to paste a cell based on another cell value
if a cell value is yes i want to copy and paste another cell value and paste it in another sheet, with this code it gets copied either way.

If Range("E17").Value = "yes" Then

MsgBox "HELLO"
xSheet.Cells(9, "E").Copy
AccSheet.Cells(AccLastRow + 1, "O").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("E9:E15").ClearContents

Else

'clear cells after adding
Range("E9:E15").ClearContents
Exit Sub

End If
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Welcome to the Board!

Your code has some variables that are not defined or set in the block of code you are showing us.
Can you post your entire code block (using code tags for readability - see here: https://www.mrexcel.com/board/help/how-to-post-your-vba-code/)?

And then can you post sample data?

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Welcome to the Board!

Your code has some variables that are not defined or set in the block of code you are showing us.
Can you post your entire code block (using code tags for readability - see here: https://www.mrexcel.com/board/help/how-to-post-your-vba-code/)?

And then can you post sample data?

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
thank you so much and yes you are right it was a mistake from the code before this sub and i solved it.
again thank you so much and this is a very nice forum it is a great help.
 
Upvote 0
You are welcome.
I am glad you were able to solve your own problem.
 
Upvote 0

Forum statistics

Threads
1,214,974
Messages
6,122,536
Members
449,088
Latest member
RandomExceller01

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