Convert selected cells formula to value across Selected Sheets












3















I'm using this code below to convert formula to cells, which works fine in a single sheet. But the problem is when I need to convert all selected cells which are in different sheets to their value, this code doesn't do it.



This is how I am selecting the cells in Excel:
first I select the cells in one sheet, than I go down to the tabs right-click and select specific sheets, which in Excel selects the corresponding cells in every selected sheet.



So any tips on how I can change this code to make it work across different sheets?



Sub formulaToValues()
If Selection.Cells.Count = 1 Then
Selection.Value = Selection.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Else
For Each cel In Selection.Cells
cel.Value = cel.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Next cel
End If
End Sub









share|improve this question

























  • Are the cells always in the same location on each sheet?

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:03











  • Does every worksheet in the workbook need to be formatted or only those selected?

    – rohrl77
    Nov 20 '18 at 7:17











  • @K.Dᴀᴠɪs yes, they are always in the same location

    – CKCCN
    Nov 20 '18 at 7:42











  • @rohrl77 I would prefer only those selected

    – CKCCN
    Nov 20 '18 at 7:43











  • Thanks for clarifying that you wanted selected sheets - I updated your question and my answer.

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:49
















3















I'm using this code below to convert formula to cells, which works fine in a single sheet. But the problem is when I need to convert all selected cells which are in different sheets to their value, this code doesn't do it.



This is how I am selecting the cells in Excel:
first I select the cells in one sheet, than I go down to the tabs right-click and select specific sheets, which in Excel selects the corresponding cells in every selected sheet.



So any tips on how I can change this code to make it work across different sheets?



Sub formulaToValues()
If Selection.Cells.Count = 1 Then
Selection.Value = Selection.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Else
For Each cel In Selection.Cells
cel.Value = cel.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Next cel
End If
End Sub









share|improve this question

























  • Are the cells always in the same location on each sheet?

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:03











  • Does every worksheet in the workbook need to be formatted or only those selected?

    – rohrl77
    Nov 20 '18 at 7:17











  • @K.Dᴀᴠɪs yes, they are always in the same location

    – CKCCN
    Nov 20 '18 at 7:42











  • @rohrl77 I would prefer only those selected

    – CKCCN
    Nov 20 '18 at 7:43











  • Thanks for clarifying that you wanted selected sheets - I updated your question and my answer.

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:49














3












3








3


1






I'm using this code below to convert formula to cells, which works fine in a single sheet. But the problem is when I need to convert all selected cells which are in different sheets to their value, this code doesn't do it.



This is how I am selecting the cells in Excel:
first I select the cells in one sheet, than I go down to the tabs right-click and select specific sheets, which in Excel selects the corresponding cells in every selected sheet.



So any tips on how I can change this code to make it work across different sheets?



Sub formulaToValues()
If Selection.Cells.Count = 1 Then
Selection.Value = Selection.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Else
For Each cel In Selection.Cells
cel.Value = cel.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Next cel
End If
End Sub









share|improve this question
















I'm using this code below to convert formula to cells, which works fine in a single sheet. But the problem is when I need to convert all selected cells which are in different sheets to their value, this code doesn't do it.



This is how I am selecting the cells in Excel:
first I select the cells in one sheet, than I go down to the tabs right-click and select specific sheets, which in Excel selects the corresponding cells in every selected sheet.



So any tips on how I can change this code to make it work across different sheets?



Sub formulaToValues()
If Selection.Cells.Count = 1 Then
Selection.Value = Selection.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Else
For Each cel In Selection.Cells
cel.Value = cel.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Next cel
End If
End Sub






excel vba selection






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 7:48









K.Dᴀᴠɪs

7,250112439




7,250112439










asked Nov 20 '18 at 6:41









CKCCNCKCCN

162




162













  • Are the cells always in the same location on each sheet?

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:03











  • Does every worksheet in the workbook need to be formatted or only those selected?

    – rohrl77
    Nov 20 '18 at 7:17











  • @K.Dᴀᴠɪs yes, they are always in the same location

    – CKCCN
    Nov 20 '18 at 7:42











  • @rohrl77 I would prefer only those selected

    – CKCCN
    Nov 20 '18 at 7:43











  • Thanks for clarifying that you wanted selected sheets - I updated your question and my answer.

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:49



















  • Are the cells always in the same location on each sheet?

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:03











  • Does every worksheet in the workbook need to be formatted or only those selected?

    – rohrl77
    Nov 20 '18 at 7:17











  • @K.Dᴀᴠɪs yes, they are always in the same location

    – CKCCN
    Nov 20 '18 at 7:42











  • @rohrl77 I would prefer only those selected

    – CKCCN
    Nov 20 '18 at 7:43











  • Thanks for clarifying that you wanted selected sheets - I updated your question and my answer.

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:49

















Are the cells always in the same location on each sheet?

– K.Dᴀᴠɪs
Nov 20 '18 at 7:03





Are the cells always in the same location on each sheet?

– K.Dᴀᴠɪs
Nov 20 '18 at 7:03













Does every worksheet in the workbook need to be formatted or only those selected?

– rohrl77
Nov 20 '18 at 7:17





Does every worksheet in the workbook need to be formatted or only those selected?

– rohrl77
Nov 20 '18 at 7:17













@K.Dᴀᴠɪs yes, they are always in the same location

– CKCCN
Nov 20 '18 at 7:42





@K.Dᴀᴠɪs yes, they are always in the same location

– CKCCN
Nov 20 '18 at 7:42













@rohrl77 I would prefer only those selected

– CKCCN
Nov 20 '18 at 7:43





@rohrl77 I would prefer only those selected

– CKCCN
Nov 20 '18 at 7:43













Thanks for clarifying that you wanted selected sheets - I updated your question and my answer.

– K.Dᴀᴠɪs
Nov 20 '18 at 7:49





Thanks for clarifying that you wanted selected sheets - I updated your question and my answer.

– K.Dᴀᴠɪs
Nov 20 '18 at 7:49












3 Answers
3






active

oldest

votes


















2














You should be able to just grab the address of the selection, then add that to each worksheet's range



Sub formulaToValues()

Dim celAddr As String
celAddr = Selection.Address

Dim ws As Worksheet
For Each ws In ActiveWindow.SelectedSheets
With ws.Range(celAddr)
.Value = .Value
.Interior.ColorIndex = 0
.Font.Color = vbBlack
End With
Next ws

End Sub





share|improve this answer





















  • 1





    .value = .value is not required?

    – shrivallabha.redij
    Nov 20 '18 at 7:09











  • No, it would be the same thing as saying Apple = Apple - only because the origination range is the same as the destination range..---- Scratch that, I see that he was using a formula - thanks for pointing that out, edit coming soon.

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:10













  • @K.Dᴀᴠɪs If there are sheets in the workbook that don't need to be changed, then this doesn't work. Neither does my answer for that matter.

    – rohrl77
    Nov 20 '18 at 7:18











  • @rohrl77 The question does state "and select all sheets, which in excel selects the corresponding cells in every sheet", so I think we are both correct. And the title: "... across all sheets"

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:19








  • 1





    @K.Dᴀᴠɪs OH! Ok. I updated my answer to take only those that are selected... which was interesting to learn. I'll just include both versions.

    – rohrl77
    Nov 20 '18 at 7:24



















1














You are attempting to write to a 3D cell collection. An interesting problem i haven't seen before. I gave it a shot.



The below code works for me. I have simply added an extra loop to search through any other sheets. Note: it is good practice to always declare your variables.



Answer1: This cycles through every sheet in the workbook



Sub formulaToValues()
Dim cel As Range
Dim ws As Worksheet
If Selection.Cells.Count = 1 Then
Selection.Value = Selection.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Else
For Each ws In ThisWorkbook.Worksheets
For Each cel In Selection.Cells
ws.Range(cel.Address).Value = 2 'cel.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Next cel
Next ws
End If

End Sub


Answer2: With this one it only goes throug the selected sheets



Sub formulaToValues()
Dim cel As Range
Dim ws As Worksheet
If Selection.Cells.Count = 1 Then
Selection.Value = Selection.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Else
For Each ws In ThisWorkbook.Windows(1).SelectedSheets
For Each cel In Selection.Cells
ws.Range(cel.Address).Value = 2 'cel.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Next cel
Next ws
End If

End Sub





share|improve this answer


























  • I actually did try to loop through the workbook too but I am too newb and couldn't get it to work, guess some mistakes was there with mine. And in my case this did the job for me. Thanks for this.

    – CKCCN
    Nov 20 '18 at 8:28











  • Hi CKCCN, glad to help. It was an interesting problem to see. One that i had not thought about before.

    – rohrl77
    Nov 20 '18 at 8:54



















0














Thanks alot guys, this got answered pretty quickly.
I am placing my macros in personal so I ended if with this



Sub formulaToValues3()
Dim cel As Range
Dim ws As Worksheet
If Selection.Cells.Count = 1 Then
Selection.Value = Selection.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Else
For Each ws In ActiveWorkbook.Windows(1).SelectedSheets
For Each cel In Selection.Cells
ws.Range(cel.Address).Value = ws.Range(cel.Address).Value 'cel.Value
Selection.Cells.Interior.ColorIndex = 0
Selection.Cells.Font.Color = vbBlack
Next cel
Next ws
End If

End Sub





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387564%2fconvert-selected-cells-formula-to-value-across-selected-sheets%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You should be able to just grab the address of the selection, then add that to each worksheet's range



    Sub formulaToValues()

    Dim celAddr As String
    celAddr = Selection.Address

    Dim ws As Worksheet
    For Each ws In ActiveWindow.SelectedSheets
    With ws.Range(celAddr)
    .Value = .Value
    .Interior.ColorIndex = 0
    .Font.Color = vbBlack
    End With
    Next ws

    End Sub





    share|improve this answer





















    • 1





      .value = .value is not required?

      – shrivallabha.redij
      Nov 20 '18 at 7:09











    • No, it would be the same thing as saying Apple = Apple - only because the origination range is the same as the destination range..---- Scratch that, I see that he was using a formula - thanks for pointing that out, edit coming soon.

      – K.Dᴀᴠɪs
      Nov 20 '18 at 7:10













    • @K.Dᴀᴠɪs If there are sheets in the workbook that don't need to be changed, then this doesn't work. Neither does my answer for that matter.

      – rohrl77
      Nov 20 '18 at 7:18











    • @rohrl77 The question does state "and select all sheets, which in excel selects the corresponding cells in every sheet", so I think we are both correct. And the title: "... across all sheets"

      – K.Dᴀᴠɪs
      Nov 20 '18 at 7:19








    • 1





      @K.Dᴀᴠɪs OH! Ok. I updated my answer to take only those that are selected... which was interesting to learn. I'll just include both versions.

      – rohrl77
      Nov 20 '18 at 7:24
















    2














    You should be able to just grab the address of the selection, then add that to each worksheet's range



    Sub formulaToValues()

    Dim celAddr As String
    celAddr = Selection.Address

    Dim ws As Worksheet
    For Each ws In ActiveWindow.SelectedSheets
    With ws.Range(celAddr)
    .Value = .Value
    .Interior.ColorIndex = 0
    .Font.Color = vbBlack
    End With
    Next ws

    End Sub





    share|improve this answer





















    • 1





      .value = .value is not required?

      – shrivallabha.redij
      Nov 20 '18 at 7:09











    • No, it would be the same thing as saying Apple = Apple - only because the origination range is the same as the destination range..---- Scratch that, I see that he was using a formula - thanks for pointing that out, edit coming soon.

      – K.Dᴀᴠɪs
      Nov 20 '18 at 7:10













    • @K.Dᴀᴠɪs If there are sheets in the workbook that don't need to be changed, then this doesn't work. Neither does my answer for that matter.

      – rohrl77
      Nov 20 '18 at 7:18











    • @rohrl77 The question does state "and select all sheets, which in excel selects the corresponding cells in every sheet", so I think we are both correct. And the title: "... across all sheets"

      – K.Dᴀᴠɪs
      Nov 20 '18 at 7:19








    • 1





      @K.Dᴀᴠɪs OH! Ok. I updated my answer to take only those that are selected... which was interesting to learn. I'll just include both versions.

      – rohrl77
      Nov 20 '18 at 7:24














    2












    2








    2







    You should be able to just grab the address of the selection, then add that to each worksheet's range



    Sub formulaToValues()

    Dim celAddr As String
    celAddr = Selection.Address

    Dim ws As Worksheet
    For Each ws In ActiveWindow.SelectedSheets
    With ws.Range(celAddr)
    .Value = .Value
    .Interior.ColorIndex = 0
    .Font.Color = vbBlack
    End With
    Next ws

    End Sub





    share|improve this answer















    You should be able to just grab the address of the selection, then add that to each worksheet's range



    Sub formulaToValues()

    Dim celAddr As String
    celAddr = Selection.Address

    Dim ws As Worksheet
    For Each ws In ActiveWindow.SelectedSheets
    With ws.Range(celAddr)
    .Value = .Value
    .Interior.ColorIndex = 0
    .Font.Color = vbBlack
    End With
    Next ws

    End Sub






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 20 '18 at 7:47

























    answered Nov 20 '18 at 7:08









    K.DᴀᴠɪsK.Dᴀᴠɪs

    7,250112439




    7,250112439








    • 1





      .value = .value is not required?

      – shrivallabha.redij
      Nov 20 '18 at 7:09











    • No, it would be the same thing as saying Apple = Apple - only because the origination range is the same as the destination range..---- Scratch that, I see that he was using a formula - thanks for pointing that out, edit coming soon.

      – K.Dᴀᴠɪs
      Nov 20 '18 at 7:10













    • @K.Dᴀᴠɪs If there are sheets in the workbook that don't need to be changed, then this doesn't work. Neither does my answer for that matter.

      – rohrl77
      Nov 20 '18 at 7:18











    • @rohrl77 The question does state "and select all sheets, which in excel selects the corresponding cells in every sheet", so I think we are both correct. And the title: "... across all sheets"

      – K.Dᴀᴠɪs
      Nov 20 '18 at 7:19








    • 1





      @K.Dᴀᴠɪs OH! Ok. I updated my answer to take only those that are selected... which was interesting to learn. I'll just include both versions.

      – rohrl77
      Nov 20 '18 at 7:24














    • 1





      .value = .value is not required?

      – shrivallabha.redij
      Nov 20 '18 at 7:09











    • No, it would be the same thing as saying Apple = Apple - only because the origination range is the same as the destination range..---- Scratch that, I see that he was using a formula - thanks for pointing that out, edit coming soon.

      – K.Dᴀᴠɪs
      Nov 20 '18 at 7:10













    • @K.Dᴀᴠɪs If there are sheets in the workbook that don't need to be changed, then this doesn't work. Neither does my answer for that matter.

      – rohrl77
      Nov 20 '18 at 7:18











    • @rohrl77 The question does state "and select all sheets, which in excel selects the corresponding cells in every sheet", so I think we are both correct. And the title: "... across all sheets"

      – K.Dᴀᴠɪs
      Nov 20 '18 at 7:19








    • 1





      @K.Dᴀᴠɪs OH! Ok. I updated my answer to take only those that are selected... which was interesting to learn. I'll just include both versions.

      – rohrl77
      Nov 20 '18 at 7:24








    1




    1





    .value = .value is not required?

    – shrivallabha.redij
    Nov 20 '18 at 7:09





    .value = .value is not required?

    – shrivallabha.redij
    Nov 20 '18 at 7:09













    No, it would be the same thing as saying Apple = Apple - only because the origination range is the same as the destination range..---- Scratch that, I see that he was using a formula - thanks for pointing that out, edit coming soon.

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:10







    No, it would be the same thing as saying Apple = Apple - only because the origination range is the same as the destination range..---- Scratch that, I see that he was using a formula - thanks for pointing that out, edit coming soon.

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:10















    @K.Dᴀᴠɪs If there are sheets in the workbook that don't need to be changed, then this doesn't work. Neither does my answer for that matter.

    – rohrl77
    Nov 20 '18 at 7:18





    @K.Dᴀᴠɪs If there are sheets in the workbook that don't need to be changed, then this doesn't work. Neither does my answer for that matter.

    – rohrl77
    Nov 20 '18 at 7:18













    @rohrl77 The question does state "and select all sheets, which in excel selects the corresponding cells in every sheet", so I think we are both correct. And the title: "... across all sheets"

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:19







    @rohrl77 The question does state "and select all sheets, which in excel selects the corresponding cells in every sheet", so I think we are both correct. And the title: "... across all sheets"

    – K.Dᴀᴠɪs
    Nov 20 '18 at 7:19






    1




    1





    @K.Dᴀᴠɪs OH! Ok. I updated my answer to take only those that are selected... which was interesting to learn. I'll just include both versions.

    – rohrl77
    Nov 20 '18 at 7:24





    @K.Dᴀᴠɪs OH! Ok. I updated my answer to take only those that are selected... which was interesting to learn. I'll just include both versions.

    – rohrl77
    Nov 20 '18 at 7:24













    1














    You are attempting to write to a 3D cell collection. An interesting problem i haven't seen before. I gave it a shot.



    The below code works for me. I have simply added an extra loop to search through any other sheets. Note: it is good practice to always declare your variables.



    Answer1: This cycles through every sheet in the workbook



    Sub formulaToValues()
    Dim cel As Range
    Dim ws As Worksheet
    If Selection.Cells.Count = 1 Then
    Selection.Value = Selection.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Else
    For Each ws In ThisWorkbook.Worksheets
    For Each cel In Selection.Cells
    ws.Range(cel.Address).Value = 2 'cel.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Next cel
    Next ws
    End If

    End Sub


    Answer2: With this one it only goes throug the selected sheets



    Sub formulaToValues()
    Dim cel As Range
    Dim ws As Worksheet
    If Selection.Cells.Count = 1 Then
    Selection.Value = Selection.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Else
    For Each ws In ThisWorkbook.Windows(1).SelectedSheets
    For Each cel In Selection.Cells
    ws.Range(cel.Address).Value = 2 'cel.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Next cel
    Next ws
    End If

    End Sub





    share|improve this answer


























    • I actually did try to loop through the workbook too but I am too newb and couldn't get it to work, guess some mistakes was there with mine. And in my case this did the job for me. Thanks for this.

      – CKCCN
      Nov 20 '18 at 8:28











    • Hi CKCCN, glad to help. It was an interesting problem to see. One that i had not thought about before.

      – rohrl77
      Nov 20 '18 at 8:54
















    1














    You are attempting to write to a 3D cell collection. An interesting problem i haven't seen before. I gave it a shot.



    The below code works for me. I have simply added an extra loop to search through any other sheets. Note: it is good practice to always declare your variables.



    Answer1: This cycles through every sheet in the workbook



    Sub formulaToValues()
    Dim cel As Range
    Dim ws As Worksheet
    If Selection.Cells.Count = 1 Then
    Selection.Value = Selection.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Else
    For Each ws In ThisWorkbook.Worksheets
    For Each cel In Selection.Cells
    ws.Range(cel.Address).Value = 2 'cel.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Next cel
    Next ws
    End If

    End Sub


    Answer2: With this one it only goes throug the selected sheets



    Sub formulaToValues()
    Dim cel As Range
    Dim ws As Worksheet
    If Selection.Cells.Count = 1 Then
    Selection.Value = Selection.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Else
    For Each ws In ThisWorkbook.Windows(1).SelectedSheets
    For Each cel In Selection.Cells
    ws.Range(cel.Address).Value = 2 'cel.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Next cel
    Next ws
    End If

    End Sub





    share|improve this answer


























    • I actually did try to loop through the workbook too but I am too newb and couldn't get it to work, guess some mistakes was there with mine. And in my case this did the job for me. Thanks for this.

      – CKCCN
      Nov 20 '18 at 8:28











    • Hi CKCCN, glad to help. It was an interesting problem to see. One that i had not thought about before.

      – rohrl77
      Nov 20 '18 at 8:54














    1












    1








    1







    You are attempting to write to a 3D cell collection. An interesting problem i haven't seen before. I gave it a shot.



    The below code works for me. I have simply added an extra loop to search through any other sheets. Note: it is good practice to always declare your variables.



    Answer1: This cycles through every sheet in the workbook



    Sub formulaToValues()
    Dim cel As Range
    Dim ws As Worksheet
    If Selection.Cells.Count = 1 Then
    Selection.Value = Selection.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Else
    For Each ws In ThisWorkbook.Worksheets
    For Each cel In Selection.Cells
    ws.Range(cel.Address).Value = 2 'cel.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Next cel
    Next ws
    End If

    End Sub


    Answer2: With this one it only goes throug the selected sheets



    Sub formulaToValues()
    Dim cel As Range
    Dim ws As Worksheet
    If Selection.Cells.Count = 1 Then
    Selection.Value = Selection.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Else
    For Each ws In ThisWorkbook.Windows(1).SelectedSheets
    For Each cel In Selection.Cells
    ws.Range(cel.Address).Value = 2 'cel.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Next cel
    Next ws
    End If

    End Sub





    share|improve this answer















    You are attempting to write to a 3D cell collection. An interesting problem i haven't seen before. I gave it a shot.



    The below code works for me. I have simply added an extra loop to search through any other sheets. Note: it is good practice to always declare your variables.



    Answer1: This cycles through every sheet in the workbook



    Sub formulaToValues()
    Dim cel As Range
    Dim ws As Worksheet
    If Selection.Cells.Count = 1 Then
    Selection.Value = Selection.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Else
    For Each ws In ThisWorkbook.Worksheets
    For Each cel In Selection.Cells
    ws.Range(cel.Address).Value = 2 'cel.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Next cel
    Next ws
    End If

    End Sub


    Answer2: With this one it only goes throug the selected sheets



    Sub formulaToValues()
    Dim cel As Range
    Dim ws As Worksheet
    If Selection.Cells.Count = 1 Then
    Selection.Value = Selection.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Else
    For Each ws In ThisWorkbook.Windows(1).SelectedSheets
    For Each cel In Selection.Cells
    ws.Range(cel.Address).Value = 2 'cel.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Next cel
    Next ws
    End If

    End Sub






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 20 '18 at 7:22

























    answered Nov 20 '18 at 7:07









    rohrl77rohrl77

    1,70742750




    1,70742750













    • I actually did try to loop through the workbook too but I am too newb and couldn't get it to work, guess some mistakes was there with mine. And in my case this did the job for me. Thanks for this.

      – CKCCN
      Nov 20 '18 at 8:28











    • Hi CKCCN, glad to help. It was an interesting problem to see. One that i had not thought about before.

      – rohrl77
      Nov 20 '18 at 8:54



















    • I actually did try to loop through the workbook too but I am too newb and couldn't get it to work, guess some mistakes was there with mine. And in my case this did the job for me. Thanks for this.

      – CKCCN
      Nov 20 '18 at 8:28











    • Hi CKCCN, glad to help. It was an interesting problem to see. One that i had not thought about before.

      – rohrl77
      Nov 20 '18 at 8:54

















    I actually did try to loop through the workbook too but I am too newb and couldn't get it to work, guess some mistakes was there with mine. And in my case this did the job for me. Thanks for this.

    – CKCCN
    Nov 20 '18 at 8:28





    I actually did try to loop through the workbook too but I am too newb and couldn't get it to work, guess some mistakes was there with mine. And in my case this did the job for me. Thanks for this.

    – CKCCN
    Nov 20 '18 at 8:28













    Hi CKCCN, glad to help. It was an interesting problem to see. One that i had not thought about before.

    – rohrl77
    Nov 20 '18 at 8:54





    Hi CKCCN, glad to help. It was an interesting problem to see. One that i had not thought about before.

    – rohrl77
    Nov 20 '18 at 8:54











    0














    Thanks alot guys, this got answered pretty quickly.
    I am placing my macros in personal so I ended if with this



    Sub formulaToValues3()
    Dim cel As Range
    Dim ws As Worksheet
    If Selection.Cells.Count = 1 Then
    Selection.Value = Selection.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Else
    For Each ws In ActiveWorkbook.Windows(1).SelectedSheets
    For Each cel In Selection.Cells
    ws.Range(cel.Address).Value = ws.Range(cel.Address).Value 'cel.Value
    Selection.Cells.Interior.ColorIndex = 0
    Selection.Cells.Font.Color = vbBlack
    Next cel
    Next ws
    End If

    End Sub





    share|improve this answer




























      0














      Thanks alot guys, this got answered pretty quickly.
      I am placing my macros in personal so I ended if with this



      Sub formulaToValues3()
      Dim cel As Range
      Dim ws As Worksheet
      If Selection.Cells.Count = 1 Then
      Selection.Value = Selection.Value
      Selection.Cells.Interior.ColorIndex = 0
      Selection.Cells.Font.Color = vbBlack
      Else
      For Each ws In ActiveWorkbook.Windows(1).SelectedSheets
      For Each cel In Selection.Cells
      ws.Range(cel.Address).Value = ws.Range(cel.Address).Value 'cel.Value
      Selection.Cells.Interior.ColorIndex = 0
      Selection.Cells.Font.Color = vbBlack
      Next cel
      Next ws
      End If

      End Sub





      share|improve this answer


























        0












        0








        0







        Thanks alot guys, this got answered pretty quickly.
        I am placing my macros in personal so I ended if with this



        Sub formulaToValues3()
        Dim cel As Range
        Dim ws As Worksheet
        If Selection.Cells.Count = 1 Then
        Selection.Value = Selection.Value
        Selection.Cells.Interior.ColorIndex = 0
        Selection.Cells.Font.Color = vbBlack
        Else
        For Each ws In ActiveWorkbook.Windows(1).SelectedSheets
        For Each cel In Selection.Cells
        ws.Range(cel.Address).Value = ws.Range(cel.Address).Value 'cel.Value
        Selection.Cells.Interior.ColorIndex = 0
        Selection.Cells.Font.Color = vbBlack
        Next cel
        Next ws
        End If

        End Sub





        share|improve this answer













        Thanks alot guys, this got answered pretty quickly.
        I am placing my macros in personal so I ended if with this



        Sub formulaToValues3()
        Dim cel As Range
        Dim ws As Worksheet
        If Selection.Cells.Count = 1 Then
        Selection.Value = Selection.Value
        Selection.Cells.Interior.ColorIndex = 0
        Selection.Cells.Font.Color = vbBlack
        Else
        For Each ws In ActiveWorkbook.Windows(1).SelectedSheets
        For Each cel In Selection.Cells
        ws.Range(cel.Address).Value = ws.Range(cel.Address).Value 'cel.Value
        Selection.Cells.Interior.ColorIndex = 0
        Selection.Cells.Font.Color = vbBlack
        Next cel
        Next ws
        End If

        End Sub






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 8:32









        CKCCNCKCCN

        162




        162






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387564%2fconvert-selected-cells-formula-to-value-across-selected-sheets%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?