Insert string based on column criteria

DaveMiles

New Member
Joined
Jun 22, 2018
Messages
2
Code:
r = ActiveSheet.Cells(Rows.Count, "G").End(xlUp).Row
 
For n = 1 To r
Dim s As String
Select Case Range("H",”I” & n).Text
Case "<>", "<>": s = "Open New"
End Select
If s <> "" Then Range("J" & n) = s
Next

Every row in Column G has a sequential valued that recurs. Sometimes the same row in Column H has a string and sometimes the same row in Column I has a string for one or all of the rows of the recurring value. If Column H or Column I has a string in any row that Column G has a recurring value then I want to enter the text ‘Open New’ into Column J for every row of the recurring value in Column G. As you can see, I am stuck, can you help?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
What is meant by "a sequential value that recurs"?
Post some sample data.
You can probably achieve what you want with a formula in column J.
 
Upvote 0
Welcome to the MrExcel board!

As footoo has mentioned this should be feasible with a formula. For example below, if I have interpreted your description correctly.

Excel Workbook
GHIJ
1
21Open New
31Open New
41abcOpen New
51Open New
61Open New
72
82
93Open New
103xyzOpen New
114Open New
124Open New
134sssOpen New
144dfgOpen New
154Open New
165
175
185
19
Open New



If that is the result you want but it needs to be by vba then one way would be to incorporate that formula solution into your vba:
Code:
Sub Open_New()
  Dim lr As Long
  
  lr = Range("G" & Rows.Count).End(xlUp).Row
  With Range("J2:J" & lr)
    .Formula = Replace("=IF(SUMPRODUCT(--(G$2:G$#=G2),--(H$2:H$#&I$2:I$#<>"""")),""Open New"","""")", "#", lr)
    .Value = .Value
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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