Trouble in VBA with Range().Value

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
I have a worksheet with certain columns containing formulas that I want to hardcode and store only the values. To do this, I created a named range containing the cells and then in VBA performed this operation:

Sheet1.Range("MyRange").Value = Sheet1.Range("MyRange").Value

However, this causes some issues. The problem seems to be that my range ("MyRange") contains cells that are not all adjacent to each other. So, for example, part of my range is in column C, and then another part of it in column E (but nothing in column D). The issue seems to be that it only keeps the values of the left-most cells, so it would replace what is in column E with data from column C.

Is there something I'm doing wrong with this code? Or can .Value not be used in ranges that contain non-adjacent cells?

Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
If you loop thought your range once cell at a time, it should work, i.e.:
Code:
    Dim cell As Range
    For Each cell In Sheet1.Range("MyRange")
        cell.Value = cell.Value
    Next cell
 
Upvote 0
Perhaps even loop through each area of the range..

Code:
    Dim c As Range
    For Each c In Sheet1.Range("MyRange").Areas
        c.Value = c.Value
    Next c
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

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