VBA code required

Damo10

Active Member
Joined
Dec 13, 2010
Messages
460
Hi,

I am looking for some code that will go through all the rows starting at cell E20 and execute the code that I have written if it meets the criteria then move to the next row until it finds the last populated row then move to the next column and repeat, it would then do this until it finds the last populated column.

There are currently 1100 rows and 70 columns in my sheet and need each cell to be checked.

Hope someone can help

Regards Damian
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
if the cell contains "a" and the date in the corrosponding cell in column C is the same or less than the current date change the cell content to a "h"
 
Upvote 0
Code:
Dim rng As Range, startCell As Range
Dim celAddress$, cel As Range, x#
Set rng = Range([E20], Cells(Rows.Count, Columns.Count))
Set startCell = rng.Cells(1)
Do
    Set cel = rng.Find(What:="a", After:=startCell, _
        LookIn:=xlValues, LookAt:=xlWhole)
    If cel Is Nothing Then Exit Do
    If x = 0 Then
        celAddress = cel.Address
        x = 1
    Else
        If cel.Address = celAddress Then Exit Do
        If Cells(cel.Row, "C") <= Date Then cel = "h"
    End If
    Set startCell = cel
Loop
 
Upvote 0
Hi,

I have been testing this code and have found that it always misses the first cell, is there anyway to rectify this?
 
Upvote 0
Code:
Dim rng As Range, startCell As Range
Dim celAddress$, cel As Range, x#
Set rng = Range([E20], Cells(Rows.Count, Columns.Count))
Set startCell = rng.Cells(1)
Do
    Set cel = rng.Find(What:="a", After:=startCell, _
        LookIn:=xlValues, LookAt:=xlWhole)
    If cel Is Nothing Then Exit Do
    If Cells(cel.Row, "C") <= Date Then cel = "h"
    If x = 0 Then
        celAddress = cel.Address
        x = 1
    Else
        If cel.Address = celAddress Then Exit Do
    End If
    Set startCell = cel
Loop
 
Upvote 0
Code:
Dim rng As Range, startCell As Range, rng2 As Range
Dim celAddress$, cel As Range, x#
Set rng = Range([E20], Cells(Rows.Count, Columns.Count))
Set startCell = rng.Cells(1)
Do
    Set cel = rng.Find(What:="a", After:=startCell, _
        LookIn:=xlValues, LookAt:=xlWhole)
    If cel Is Nothing Then Exit Do
    If x = 0 Then
        celAddress = cel.Address
        If Cells(cel.Row, "C") <= Date Then Set rng2 = cel
        x = 1
    Else
        If cel.Address = celAddress Then Exit Do
        If Cells(cel.Row, "C") <= Date Then Set rng2 = Union(cel, rng2)
    End If
    Set startCell = cel
Loop
rng2 = "h"
 
Upvote 0
Hi,

Just tried this code and it is giving a run time error 91 with the line rng2 = "h"

Regards
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
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