Identifying Values in a Range After Integrating Two Columns

aryaden

Board Regular
Joined
Jun 9, 2021
Messages
101
Office Version
  1. 2019
Platform
  1. Windows
My original excel worksheet looks like:
Book1345.xlsm
ABCDEF
1CategoryDescription1234
2abcd
3BasketballAAAXX
4BasketballBBBXX
5SoccerCCCCX
6SoccerDDDDX
7SoccerEEEEXX
8TennisFFFXX
9TennisGGGXX
10
Original_1


I am then using this VBA code: integrates the "Category" and "Duties" columns
VBA Code:
Sub Integrate()

    Dim lr As Long
    Dim r As Long
    Dim lc As Long
  
    Application.ScreenUpdating = False
  
'   Find last row with data in column A
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
'   Loop through data backwards
    For r = lr To 3 Step -1
'       Check to see if column A is not equal to row above it
        If (Cells(r, "A") <> "") And (Cells(r, "A") <> Cells(r - 1, "A")) Then
'           Insert blank row
            Rows(r).Insert
'           Copy value to column B
            Cells(r, "B") = Cells(r + 1, "A")
'           Copy formatting
            Cells(r + 1, "A").Copy
            Range(Cells(r, "B"), Cells(r, lc)).PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
                SkipBlanks:=False, Transpose:=False
            Application.CutCopyMode = False
        End If
    Next r
  
'   Delete column A
    Columns("A:A").Delete
  
'   Autofit columns
    Cells.EntireColumn.AutoFit
      
    Application.ScreenUpdating = True
  
End Sub

To transform the original worksheet into this:
Book1345.xlsm
ABCDE
1Description1234
2abcd
3Basketball
4AAAXX
5BBBXX
6Soccer
7CCCCX
8DDDDX
9EEEEXX
10Tennis
11FFFXX
12GGGXX
13
14
VBA_Output1


I am now trying to incorporate code into the VBA that will change the output to this: For example B6 , D6, and E6 have Xs in them because B7-B9, D7-D9 and E7-E9 all have at least one X in that range
Book1345.xlsm
ABCDE
1Description1234
2abcd
3BasketballXXXX
4AAAXX
5BBBXX
6SoccerXXX
7CCCCX
8DDDDX
9EEEEXX
10TennisXX
11FFFXX
12GGGXX
13
14
Goal_Output2


Currently I am entering the formula "=IF(COUNTIF(B4:B11, "X"), "X", " ")" into each cell of the category rows (3, 6, and 10 which are Basketball, Soccer, Tennis in example) to get to my goal output. Is there anyway to do this within the initial VBA I am using?

I have multiple worksheets where this "range" changes. For this example rows 4-5 is the Basketball Range whereas in another worksheet the range may be rows 4-7. I am trying to come up with a macro that can add in the Xs regardless of the data range. I am an intern who has many workbooks of data like this to sort and having a macro would help a lot.

Thank you so much!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,214,827
Messages
6,121,812
Members
449,048
Latest member
greyangel23

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