Help w/ automating a script based on value

boznian

Board Regular
Joined
Mar 25, 2003
Messages
167
I really don't know where to begin with this one. I am trying to reduce the overhead of unnecessary formula's in my spreadsheet for items (rows) that have long since been sold and no longer need to be re-calculated every time by replacing the formula with its text (numerical) result . So I am doing this:
Code:
    crow = ActiveCell.Row
    Application.ScreenUpdating = False
    Cells(crow, "C:C").Activate
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
'    Repeats 15 times for each row, using different column values
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
The problem is that I have to select each row manually (have ~ 5,000 rows to go through and the rows I need aren't necessarily contiguous) based on criteria in 2 columns.

Values in column C & D are both the result of formula's (if that makes a difference) and if the results of the formula in both Col C & D in the current row are "3" (either column might be blank, 0, 1, 2 or 3), then my script to replace the formula's needs to run on that row. If anything other than 3 & 3 in col C & D, then skip the row and evaluate the next, repeating until a blank row (Column A is blank) is found.

Can anyone help me with this?
 
Sorry for the delay, work and stuff...

OK, so this is what I have tried and I still get the same error as above:
"Method 'Range of Object'_Global Failed"

Code:
For Each rw In Selection.EntireRow.Rows
    If Cells(rw.Row, "C") = 3 And Cells(rw.Row, "D") = 3 Then
        For Each ar In Intersect(rw, Range("C:C,D:D,K:K,L:L,U:U,X:X,AA:AA,AC:AC,AG:AG,AH,AH,AI:AI,AJ:AJ,AK:AK,AL:AL")).Areas
            ar.Value = ar.Value
        Next ar
    End If
Next rw

Tried selecting a single row, multiple rows, leaving out cols. C and D, tried changing "Range" to "Cells", etc., but I cannot get it to run?
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Oh jeeezz - stupid mistake on my part, "...AG:AG,AH,AH,AI:AI," should have been "AH:AH" of course! Just tripped me up getting the same error message as before.

What a timesaver! Thanks p45cal!
 
Upvote 0
Didn't you notice that you have AH,AH instead of AH:AH?

In addition, why not using:

Rich (BB code):
Sub tst()
    For Each rw In Selection.EntireRow.Rows
        If Cells(rw.Row, "C") = 3 And Cells(rw.Row, "D") = 3 Then
            For Each ar In Intersect(rw, Range("C:D,K:L,U:U,X:X,AA:AA,AC:AC,AG:AL")).Areas
                ar.Value = ar.Value
            Next
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,749
Members
452,940
Latest member
rootytrip

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