• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

To apply formulas in different columns at once with vba excel and see value

Good morning, I have a file with 20 columns and more than 10 thousand records. In three columns, for example 6, 9 and 12, I need to apply formulas.
I will appreciate to apply the three formulas simultaneously to obtain the results and to see values, not the formula, for example that in F4 it is 978 and not see = B4 + D4

I would appreciate your help

Callao2908
 

Attachments

  • Libro-Chandoo_Valores.xls
    27.5 KB · Views: 12
Select Columns 6, 9 & 12
Ctrl+1, Protection
Select Hidden and Ok
Goto the Review, Protect Sheet tab
Apply a password if required
Click Ok
 
Thanks HUI, but I do not want to hide or block the columns. What I need is to apply certain formulas in those columns, with a macro, and to be able to see the results as values.
Suppose as in my example if I have 12 columns, all of which are filled with data except 6, 9 and 12, it is in these in which I want to run a macro that applies the formulas to fill all three simultaneously And can see the result as values
Sorry for my interpretation but I'm using Google Translate from Spanish to English
Thank you
Callao2908
 
If your using a macro to apply a formula, why not just add a few lines to copy the same range and paste as values after you apply the formulas

Your file has no VBA Code
 
Are you currently seeing formulas because you have toggled:
CTRL+` which (from Excel Help) alternates between displaying cell values and displaying formulas in the worksheet?

Since you've asked for a macro, this one works on the active sheet:
Code:
Sub blah()
With Intersect(Range("A1").CurrentRegion, Range("A1").CurrentRegion.Offset(1))
  .Columns(6).FormulaR1C1 = "=+RC[-4]+RC[-2]"
  .Columns(9).FormulaR1C1 = "=+RC[-6]+RC[-1]"
  .Columns(12).FormulaR1C1 = "=+RC[-5]+RC[-1]"
  With Union(.Columns(6), .Columns(9), .Columns(12))
    .Locked = True
    .FormulaHidden = True
  End With
End With
ActiveSheet.Protect
ActiveWindow.DisplayFormulas = False
End Sub
 
If you mean that values for Column 6, 9 & 12 should be calculated inside VBA macro and values placed into cells.

You can do something like below.

Code:
Sub Test()
Dim i As Integer, j As Long
Dim ResArr As Variant
myArray = Range("A2:L" & Cells(Rows.Count, 1).End(xlUp).Row)

For i = 1 To UBound(myArray, 2)
    Select Case i
        Case 6
            ReDim ResArr(UBound(myArray, 1), 1)
            For j = 1 To UBound(myArray, 1)
                ResArr(j - 1, 0) = myArray(j, 2) + myArray(j, 4)
            Next j
            Range("F2:F" & UBound(myArray, 1) + 1) = ResArr
        Case 9
            ReDim ResArr(UBound(myArray, 1), 1)
            For j = 1 To UBound(myArray, 1)
                ResArr(j - 1, 0) = myArray(j, 3) + myArray(j, 8)
            Next j
            Range("I2:I" & UBound(myArray, 1) + 1) = ResArr
        Case 12
            ReDim ResArr(UBound(myArray, 1), 1)
            For j = 1 To UBound(myArray, 1)
                ResArr(j - 1, 0) = myArray(j, 7) + myArray(j, 11)
            Next j
            Range("L2:L" & UBound(myArray, 1) + 1) = ResArr
    End Select
Next i
      
End Sub

Edit: Seems pretty quick. Did test for 10315 rows. Took about 0.03~0.05 sec.
 
Chihiro thank you so much, it's what I needed.
You can give the topic finished
Thanks until a new opportunity
I forgot to thank to Hui and p45cal
Regards Callao2908
 
Back
Top