Macro to hardcode a row based on formula output

Status
Not open for further replies.

Antonia2345

New Member
Joined
Jun 20, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a workbook that contains an excel worksheet, in which each cell in column A (starting from row 16) is a consistent formula returning "Yes" or "No" based on conditions within other worksheets.

I am trying but failing to write a macro that:

a) searches column A for rows containing the formula output "Yes" (I can search successfully for the hardcoded value "Yes", but I can't work out how to search for the formula output "Yes"), and then where it finds "Yes" in Column A, then selects that row and hardcodes the whole row

b) is triggered automatically whenever the output of a formula in column A changes to "Yes"

Can this be done?

Please help!
 
Yes! Thank you - this is working nicely and it is fast. Problem solved, I really appreciate your help
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Glad we could help & thanks for the feedback.
 
Upvote 0
Hi, I know I'm coming at this late in the game but I receive an error using this code and I don't know enough VBA to troubleshoot. Says Compile error: Argument not optional

Sub CopyPasteCompleted()
Dim Cl As Range, Rng As Range

On Error Resume Next
Set Rng = Range("A:A").SpecialCells(xlFormulas)
On Error GoTo 0
If Rng Is Nothing Then Exit Sub
For Each Cl In Range
If Cl.Value = "Complete" Then
Cl.EntireRow.Value = Cl.EntireRow.Value
End If
Next Cl
End Sub
 
Upvote 0
This line is wrong:
VBA Code:
For Each Cl In Range
Range is function that requires an argument of which there are many options , I think what you really mean is to loop through the range you have just set up in the variable Rng, so try:
VBA Code:
For Each Cl In Rng
 
Upvote 0
This line is wrong:
VBA Code:
For Each Cl In Range
Range is function that requires an argument of which there are many options , I think what you really mean is to loop through the range you have just set up in the variable Rng, so try:
VBA Code:
For Each Cl In Rng
This does resolve the error for me but the macro doesn't seem to be working as designed. My "Complete" rows still have formulas.
 
Upvote 0
I have understood what you are trying to do, your code as it stands doesn't work because you set the range in column A just to include where you have got a formula so when you test for the text "Complete" it never finds it. Try this which checks every line for complete. I have detected the last line with values in it because it is much faster than doing the entire column:
VBA Code:
Sub CopyPasteCompleted()
Dim Cl As Range, Rng As Range

On Error Resume Next
lastrow = Cells(Rows.Count, "A").End(xlUp).Row

Set Rng = Range("A1:A" & lastrow)
On Error GoTo 0
If Rng Is Nothing Then Exit Sub
For Each Cl In Rng
If Cl.Value = "Complete" Then
Cl.EntireRow.Value = Cl.EntireRow.Value
End If
Next Cl
End Sub
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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