VBA help

AussieVic

Active Member
Joined
Jan 9, 2009
Messages
364
Hi, how can i get the below code to convert formulas to values?

Code:
With Sh
    i = .Range("N65536").End(xlUp).Row
    'Debug.Print i
    theformula = "=IF(ISNUMBER(MATCH(RC[-5],[Rec_Update.xls]Asset!C4,0)),"""",""CLEARED"")"
    
    For Each c In .Range("S8:S" & i)
        'Debug.Print c.Row
        cellValue = Val(CStr(c.Offset(0, -5).Value))
        If cellValue > 0 Then
            c.FormulaArray = theformula
            Application.DisplayAlerts = False
        End If
    Next c
    
End With
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi, how can i get the below code to convert formulas to values?

Code:
With Sh
    i = .Range("N65536").End(xlUp).Row
    'Debug.Print i
    theformula = "=IF(ISNUMBER(MATCH(RC[-5],[Rec_Update.xls]Asset!C4,0)),"""",""CLEARED"")"
 
    For Each c In .Range("S8:S" & i)
        'Debug.Print c.Row
        cellValue = Val(CStr(c.Offset(0, -5).Value))
        If cellValue > 0 Then
            c.FormulaArray = theformula
            Application.DisplayAlerts = False
        End If
    Next c
 
End With

Can you record copy>paste special>values and insert it into the code, something like this:-

Code:
Columns("N:N").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Last edited:
Upvote 0
Rich (BB code):
With Sh
    i = .Range("N65536").End(xlUp).Row
    'Debug.Print i
    theformula = "=IF(ISNUMBER(MATCH(RC[-5],[Rec_Update.xls]Asset!C4,0)),"""",""CLEARED"")"
    
    For Each c In .Range("S8:S" & i)
        'Debug.Print c.Row
        cellValue = Val(CStr(c.Offset(0, -5).Value))
        If cellValue > 0 Then
            c.FormulaArray = theformula
            c.Value = c.Value
            Application.DisplayAlerts = False
        End If
    Next c

End With
 
Upvote 0
Out of interest mirabeau, I am still learning also can what I suggested be done also?
 
Upvote 0
Out of interest mirabeau, I am still learning also can what I suggested be done also?
Hi dazwm,

I guess we can all learn something from the posts on this forum.

My post wasn't because there was anything wrong with your suggestion, but just to indicate another approach.

Your approach should work OK to answer the question as asked.

I can make a couple of comments that may be of interest to you.
1. Usually it's not necessary or desirable use selections in VBA code.
Your code could be
Code:
With Columns("N:N")
    .Copy
    .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
End With

or equivalently, if you want to reduce that by a couple lines

    Columns("N:N").Copy
    Columns("N:N").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False

or just Range("N1") would do for the paste procedure since only the leading cell is needed.

2. Copying and pasting involves more typing and more operations, which may slow the code if it's being done a lot, say like 100k times in the same code.

3. Copying replaces whatever is on the clipboard, and this may be something that was useful otherwise, say to use in another part of the code where it may be more efficiently used.
 
Upvote 0
Thanks

Rich (BB code):
With Sh
    i = .Range("N65536").End(xlUp).Row
    'Debug.Print i
    theformula = "=IF(ISNUMBER(MATCH(RC[-5],[Rec_Update.xls]Asset!C4,0)),"""",""CLEARED"")"
    
    For Each c In .Range("S8:S" & i)
        'Debug.Print c.Row
        cellValue = Val(CStr(c.Offset(0, -5).Value))
        If cellValue > 0 Then
            c.FormulaArray = theformula
            c.Value = c.Value
            Application.DisplayAlerts = False
        End If
    Next c
End With
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,904
Members
452,948
Latest member
Dupuhini

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