Vba Code if info in cell go to the next one and write something loop

Zuzazuza

New Member
Joined
Jun 4, 2021
Messages
1
Office Version
  1. 2019
  2. 2016
Hello all,


I have managed to arrange a report with multiple changing data.
After i set a filter on column L on N/A(items not captured in the original formula) i need to check for comments in column K, if there is a comment(some cells are blank), i usually have one out of 3 names there, so it should populate the L cell next to it with the name.

Eg.
filter on N/A
K5,K8,K10 are blank K15 has comment "bla bla bla John Google", i need it to take the name and copy it in L15, only the name John Google. After that in needs to loop until the end of the report which is never the same amount of data.

Could you please help ?
 

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.
Hi Zuzazuza,

I created a quick table below with the error '#N/A' in column 'Error Column' and the comment with a name at the end in column 'Comment'.

By formatting the data as a table it does not matter if there is one or a thousand entries it will always loop through the entire column. Running the code below it loops through the entire 'Error Column' (no need to filter it) and checks if the value in the cell is an error and there is also a comment. If it is an error and a there is a comment it returns the last two words (assumed the name is always two words and last in the comment) from the 'Comments' column. If there is no comment it skips it.

Row 6 below has no comment so it skips this error whereas row 8 has a comment and it has returnd the name Bob Bing.

1623024436736.png


VBA Code:
Sub CheckforError()

For Each i In Sheet1.Range("table2[Error Column]") '** Name of the column here so it will always check every entry no matter how many entires in the table

    Comment = i.Offset(0, 1).Value '** change the number 1 depending on how many columns over the comment is with the name
        
    If IsError(i.Value) And Comment <> "" Then '** Check that there is an error and there is text in the comment
    
    Name = Split(Comment, " ")
    i.Value = Name(UBound(Name) - 1) & " " & Name(UBound(Name))

    End If
    
Next i

End Sub

Steven
 

Attachments

  • 1623023683226.png
    1623023683226.png
    18.7 KB · Views: 5
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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