Most Frequent Cell with conditional

JODomingos

New Member
Joined
Jul 11, 2020
Messages
48
Office Version
  1. 2016
Platform
  1. Windows
Hi Fellows.

I need a help to design a VBA macro for the following issue: I want to Unify rows 4 and 5 (SourceA), based on the condition:

When the cell B4 and B5 have "AA" ; "CC" ; "GG" ; "TT" then get the most frequent in the column of source A range and put into third cell below(Most frequent), make a loop for all cells right until the last column filled.

If B4 or B5 have anything different of "AA" ; "CC" ; "GG" ; "TT" then consider just the cell with the double letter.

Besides that i would like to perform that macro for many Sources in coluns A.

See in the picture the expected result.

Really Thank you in advance.

1596821556271.png
 

Attachments

  • 1596821527899.png
    1596821527899.png
    16.5 KB · Views: 3
Almost there Friend! The script worked very well but when there is cases like column B and D, which it should be expected to fill with "AT" it results a empty cell.
I really thank you again.


1599135348380.png
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try this. my fault an error in the formula:

Rich (BB code):
Sub Most_Frequent()
  Dim a As Range, lc As Long
  Dim s1 As String, s2 As String
  Dim fst As String, snd As String

  fst = ",AA,CC,GG,TT,"
  snd = ",AT,CA,CG,GC,GT,AG,"
  
  lc = Cells(3, Columns.Count).End(1).Column
  For Each a In Range("A4", Range("A" & Rows.Count).End(3)).SpecialCells(xlCellTypeConstants).Areas
    With a.Cells(a.Rows.Count).Offset(, 1).Resize(1, lc - 1)
      s1 = a.Offset(0, 1).Cells(1).Address(0, 0)
      s2 = a.Offset(1, 1).Cells(1).Address(0, 0)
      .Formula = "=IF(ISNUMBER(SEARCH("",""&" & s1 & "&"","",""" & fst & """))," & s1 & _
                 ",IF(ISNUMBER(SEARCH("",""&" & s2 & "&"","",""" & fst & """))," & s2 & _
                 ",IF(ISNUMBER(SEARCH("",""&" & s1 & "&"","",""" & snd & """))," & s1 & _
                 ",IF(ISNUMBER(SEARCH("",""&" & s2 & "&"","",""" & snd & """))," & s2 & ",""""))))"
      .Value = .Value
    End With
  Next
End Sub
 
Upvote 0
Hi Friend, Almost There! Column B and D should be filled with "AT", but it results in empty cell.

I really thank you.


1599137674479.png
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

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