Conditional replacing a certain value in a certain columns

sprimax

New Member
Joined
Oct 3, 2008
Messages
41
Hi folks,

Let's say I have a bunch of data with header from row #1-5, and the data to process starting from column E to AZ. How to replace whatever value with "YES", if the the character within each cell is more than 2 digit using VBA?

I am using MS Excel 2007.

Thanks in advance
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this

Code:
    Dim MyRange As Range
    Dim Cell As Range
 
    Set MyRange = Range("E1:AZ5")
    For Each Cell In MyRange
        If Len(Cell) > 2 Then
            Cell.Value = "YES"
        End If
    Next Cell
 
Upvote 0
Dear Gsbelbin,

Thanks for the code, it works. But it takes 2 minutes just to manage E6:AZ1000. Is there any possibilities to make it faster ?

Thank you
 
Upvote 0
Try using Application.ScreenUpdating = False/True like this

Code:
Dim MyRange As Range
    Dim Cell As Range
    
    Application.ScreenUpdating = False
    Set MyRange = Range("E1:AZ5")
    For Each Cell In MyRange
        If Len(Cell) > 2 Then
            Cell.Value = "YES"
        End If
    Next Cell
    Application.ScreenUpdating = True
 
Upvote 0
2 minutes, even though I added
Application.ScreenUpdating = False
" code "
Application.ScreenUpdating = True
 
Upvote 0
I've tried filling all those cells with data and run the code and it only takes a couple of seconds, and that's on a 9 year old PC:) What exactly is in the cells that are being updated? Do you have other formulas that use the contents of those cells? My guess is that there is something else going on that is causing the delay.

Edit
You could maybe try

Application.Calculation = xlCalculationManual

and

Application.Calculation = xlCalculationAutomatic

In place of the ScreenUpdating lines
 
Last edited:
Upvote 0

Forum statistics

Threads
1,225,685
Messages
6,186,427
Members
453,354
Latest member
Ubermensch22

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