Macro run only if the data is available in another cell

amandeep08

Board Regular
Joined
Mar 20, 2011
Messages
130
Office Version
  1. 365
I Have one macro. I want that if the data in Column P is non blank only then this macro run on respective cell in column Q. If the cell is blank in column P, then same row in column Q will be blank. Below is the macro

Sub OddRowAlert()
With Range("q2:q100")
.Formula = "=IF((MOD(ROW(q2),2)),""B"",""A"")"
.Formula = .Value
End With
End Sub

Pl help
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi
How about
VBA Code:
Sub OddRowAlert()
With Range("q2:q100")
.Formula = "=IF(P2<>"""",IF((MOD(ROW(Q2),2)),""B"",""A""),"""")"
.Formula = .Value
End With
End Sub
 
Upvote 0
Hi amandeep08,


maybe

VBA Code:
Sub OddRowAlert_FormulasColP()
On Error Resume Next
With Range("p2:p100").SpecialCells(xlCellTypeFormulas, 23)
  .Offset(0, 1).Formula = "=IF((MOD(ROW(q2),2)),""B"",""A"")"
  Range("q2:q100").Value = Range("q2:q100").Value
End With
End Sub

VBA Code:
Sub OddRowAlert_ValuesColP()
On Error Resume Next
Range("p2:p100").SpecialCells(xlCellTypeConstants, 23).Offset(0, 1).Formula = "=IF((MOD(ROW(q2),2)),""B"",""A"")"
With Range("q2:q100")
  .Value = .Value
End With
End Sub

Holger
 
Last edited:
Upvote 0
Hi
How about
VBA Code:
Sub OddRowAlert()
With Range("q2:q100")
.Formula = "=IF(P2<>"""",IF((MOD(ROW(Q2),2)),""B"",""A""),"""")"
.Formula = .Value
End With
End Sub
Thanks. This is working as per the expectation
 
Upvote 0
You Are very welcome
And thank you for the feedback
Be happy and safe
Happy new year
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,813
Members
449,469
Latest member
Kingwi11y

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