Excel Macro to set a Flag

sivaraj43

New Member
Joined
Feb 3, 2005
Messages
1
I have an excel sheet with three columns- (the employee number, e-mail id and flag).

I need the cells of the flag field to be set to one if the cells of the either the employee number or the email-id is empty. If either of the cells of employee number or the email-id contains an entry, the flag need not be set.

I need to write this in a Macro and not as a formula. Can someone help me out?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Well, you didn't give any details about specific columns or ranges, so if by chance this is column C for Flags, and if by chance your data starts in row 1, try this for starters:

Sub Test1()
Dim LR As Long
LR = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row
Range("C1:C" & LR).Formula = "=IF(COUNTA(RC1:RC2)<2,1,"""")"
End Sub


If you want the Flag value of 1 to be a constant and not a formula, try this instead:

Sub Test2()
Dim LR As Long
LR = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row
With Range("C1:C" & LR)
.Formula = "=IF(COUNTA(RC1:RC2)<2,1,"""")"
.Value = .Value
End With
End Sub
 
Upvote 0
Assume the the flag range is C1:C10. Try this code (in the sheet module):

Sub SetFlag()
[c1].Formula = "=if((len(A1)+len(B1)),char(32),1)"
[c1].Copy [c2:c10]
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,570
Latest member
rik81h

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