VBA Copy paste special values based on cell reference

benwork

Board Regular
Joined
Oct 8, 2010
Messages
69
Hi all,

I'm a bit stuck on some code where I'm trying to copy paste special (remove the formulas) of a range based on a cell value.

If the cell value (DB626:DL626) is "Yes" then I want to copy paste special (or another way to lock in the values) of the column with a row range of 51:625

As an example, if DD597 = yes, then I want DD51:DD625 to be copy paste values to remove the formulas.

Is there a way to do this?

Thanks in advanced
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi,

I need followings to be refined:
- "If the cell value (DB626:DL626) is "Yes" then..." I suppose if one or more cell= "Yes" in that range then VBA code should do what you requested. Is that right?
- "
As an example, if DD597 = yes, then...": Earlier you mentioned range DB626:DL626. What is the exact range where you want to check "Yes"?
- "...
another way to lock in the values": which solution do you prefer: copy-paste formulas as values or lock those cells and protect worksheet?

Thanks.
 
Upvote 0
Hi,

I need followings to be refined:
- "If the cell value (DB626:DL626) is "Yes" then..." I suppose if one or more cell= "Yes" in that range then VBA code should do what you requested. Is that right?
- "
As an example, if DD597 = yes, then...": Earlier you mentioned range DB626:DL626. What is the exact range where you want to check "Yes"?
- "...
another way to lock in the values": which solution do you prefer: copy-paste formulas as values or lock those cells and protect worksheet?

Thanks.

Thanks for the reply, I've been working long hours and I feel like my brain is mush and apparently Im tying that way too :)

1) There could be multiple columns with the yes value and all the columns with yes would then need to be copy paste values
2) Typo on my behalf, range is DB626:DL626 - the 597 comment was incorrect
3) Copy paste values is what is required

Hope this clarifies the original post.

Thanks in advanced

Cheers

Ben
 
Upvote 0
Hi Ben,

Please see code below:

Code:
Sub CopyPasteValues()


Dim cRange As Range, c As Range, actSheet As Worksheet


Application.ScreenUpdating = False


Set actSheet = ThisWorkbook.Worksheets("Sheet1") 'change sheet name if necessary
Set cRange = actSheet.Range("DB626:DL626") 'change range if necessary


For Each c In cRange.Cells
    If c.Value = "Yes" Then
        actSheet.Range(Cells(51, c.Column), Cells(625, c.Column)) = _
        actSheet.Range(Cells(51, c.Column), Cells(625, c.Column)).Value
    End If
Next c


Application.ScreenUpdating = True


End Sub

Cheers,
 
Upvote 0
Hi Ben,

Please see code below:

Code:
Sub CopyPasteValues()


Dim cRange As Range, c As Range, actSheet As Worksheet


Application.ScreenUpdating = False


Set actSheet = ThisWorkbook.Worksheets("Sheet1") 'change sheet name if necessary
Set cRange = actSheet.Range("DB626:DL626") 'change range if necessary


For Each c In cRange.Cells
    If c.Value = "Yes" Then
        actSheet.Range(Cells(51, c.Column), Cells(625, c.Column)) = _
        actSheet.Range(Cells(51, c.Column), Cells(625, c.Column)).Value
    End If
Next c


Application.ScreenUpdating = True


End Sub

Cheers,

Thank you very much,

worked perfectly

Cheers
 
Upvote 0

Forum statistics

Threads
1,215,721
Messages
6,126,461
Members
449,315
Latest member
misterzim

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