Loop thru Mult Ranges and save as valus

Grimm127

Board Regular
Joined
Aug 17, 2011
Messages
132
Hello Gurus!

I am a VBAmature and in need of your genius, lol.


I have a set of various ranges that I need to set to save as values. My current set up as follows. However the problem is that I can't paste values in multiple ranges.

So I need something that loops through each range and saves those ranges as values. How can I do this?

'PNL1
Range("A6:AC8,A10:AC11,A13:AC13,A16:AC19,A21:AC22,A25:AC28,A30:AC30,A298:AC300,A302:AC303,A305:AC305,A308:AC311,A313:AC314,A317:AC320,A322:AC322").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
How about
Code:
Sub Tstt()
    
    Dim Cl As Range

    For Each Cl In Range("A6:AC8,A10:AC11,A13:AC13,A16:AC19,A21:AC22,A25:AC28,A30:AC30,A298:AC300,A302:AC303,A305:AC305,A308:AC311,A313:AC314,A317 :AC320,A322:AC322")
        Cl.Value = Cl.Value
    Next Cl
    
End Sub
 
Upvote 0
perhaps something like....

Code:
Sub test()
Dim c As Range
Dim rng As Range
Set rng = Range("d7:f12,g1:h21")
For Each c In rng.Cells
    c = c.Value
Next
End Sub
 
Upvote 0
How about
Code:
Sub Tstt()
    
    Dim Cl As Range

    For Each Cl In Range("A6:AC8,A10:AC11,A13:AC13,A16:AC19,A21:AC22,A25:AC28,A30:AC30,A298:AC300,A302:AC303,A305:AC305,A308:AC311,A313:AC314,A317 :AC320,A322:AC322")
        Cl.Value = Cl.Value
    Next Cl
    
End Sub

Thank you for the suggestion, the problem I am finding is that its going cell by cell to convert to values and its taking too long. It does work however.
 
Upvote 0
Thank you for the suggestion.
But like the other code since its going cell by cell to covert to values its taking too long to calc. Is there any other options? It does work as you have it.
 
Upvote 0
When working with discontinuous ranges, one can use Areas

Code:
Dim oneArea as Range

For Each oneArea in  Range("A6:AC8,A10:AC11,A13:AC13,A16:AC19,A21:AC22,A25:AC28,A30:AC30,A298:AC300,A302:AC303,A305:AC305,A308:AC311,A313:AC314,A317 :AC320,A322:AC322").Areas
    oneArea.Value = oneArea.Value
Next oneArea

Another option would be to do the whole included range at one go, if the intermediate cells (AC9 for example) do not have formulas

Code:
With  Range("A6:AC8,A10:AC11,A13:AC13,A16:AC19,A21:AC22,A25:AC28,A30:AC30,A298:AC300,A302:AC303,A305:AC305,A308:AC311,A313:AC314,A317 :AC320,A322:AC322")
    With Range(.Cells, .Cells)
        .Value = .Value
    End With
End With
 
Last edited:
Upvote 0
Wow! I never heard of Areas. It works perfectly. Thank you for the solution. I really appreciated it!!
 
Upvote 0
I usually start and end cell updating routines by chaning the Calculation mode....
before the loop:

Application.Calculation = xlCalculationManual

then after the loop:

Application.Calculation = xlCalculationAutomatic
 
Upvote 0
I usually start and end cell updating routines by chaning the Calculation mode....
before the loop:

Application.Calculation = xlCalculationManual

then after the loop:

Application.Calculation = xlCalculationAutomatic

Will that improve the timing issue? The number of ranges I have are 60 per table, with 7 tables in each tab
 
Upvote 0
Yes. Will it be noticeable? It depends on how many formulas you have in your workbook... how long it takes to recalculate the whole workbook...
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
Latest member
laura12345

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