IF COUNTA conversion to VBA

gabbana

New Member
Joined
Feb 5, 2016
Messages
5
Morning All,

Can anyone help convert this into VBA for me? I need it to automatically run as the worksheet is filled out:

Code:
=IF(COUNTA(M1:V1)=10,TODAY()+60,"")

Currently used in column W Thanks in advance.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I take it you plan to fill out a section within the worksheet (e.g. not the header row, so only row 2 onwards?), then have the results of this added to a specific column on the same row. I ask because this is a simple request but will need a number of conditions considered, such as what happens if you enter multiple rows at same time, or what happens if you change the cell that this macro writes to?

Try this. It appears to work, but you should always save your work before running untested code. Paste it into the worksheet code module for the sheet that you want it to run on

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cl As Range, rngDest As Range, r As Long

Application.EnableEvents = False ' prevent chance of terminal loops

For Each cl In Target
    r = cl.Row
    If r >= 2 And cl.Column <> 23 Then ' only look at row 2 onwards, ignore column W
        
        Set rngDest = Range(Cells(r, 13), Cells(r, 22)) ' create range of cells to be looked at (columns M to V)
        
        If WorksheetFunction.CountA(rngDest) = 10 Then
            Cells(r, 23) = Date + 60 ' enter value
        Else
            Cells(r, 23).ClearContents ' clear value
        End If
        
    End If
Next cl

Application.EnableEvents = True ' return setting to default

End Sub
 
Upvote 0
Thank you. This works perfectly. The start row needed to be amended, but I worked that bit out.

The cells it references are dates which certain tasks are completed. The date it generates is a 60 day review date upon completion of the last task. (they are all done by different people at different times, so it was a way of ensuring a review is complete.

I had to use VBA as a cell formula kept updating the date every time I opened the sheet.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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