Check two columns value and add them into Rows

excel_kal

New Member
Joined
Jul 14, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I need to check the values in multiple columns and if the data is there then need to add them in Rows in Diff sheet. Below is the example data set and expected. I have tried with Index & match still not able to get the expected result. Any suggestions will be helpful.

1594710178781.png


Thanks
kal
 

Attachments

  • 1594709548396.png
    1594709548396.png
    6.5 KB · Views: 3

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 and welcome to MrExce.

Libro1
ABCDEFGHIJK
1Customer30 day date30 day id60 day Date60 day id90 day date90 day idmisc1 datemisc1 idmisc2 datemisc2 id
2Name 105-jun12306-jul345
3Name 206-jun657
4Name 310-jun78912-jun890
5Name 110-jun432
6Name 520-jul987
Data Set


Assuming your data starts in cell A1 on the "Data Set" sheet.
The results on the "Result" sheet.
Adjust the names of your sheets in the macro.

VBA Code:
Sub Check_two_columns()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long, lr As Long, lc As Long
 
  With Sheets("Data Set")
    lr = .Range("A" & Rows.Count).End(3).Row
    lc = .Cells(1, Columns.Count).End(1).Column
    a = .Range("A1", .Cells(lr, lc)).Value2
  End With
  ReDim b(1 To lr * lc, 1 To 3)
 
  For i = 2 To UBound(a, 1)
    For j = 2 To UBound(a, 2) Step 2
      If a(i, j) <> "" Then
        k = k + 1
        b(k, 1) = Replace(a(1, j), "date", "", , , vbTextCompare)
        b(k, 2) = a(i, j)
        b(k, 3) = a(i, j + 1)
      End If
    Next j
  Next i
    
  Sheets("Result").Range("A2").Resize(k, 3).Value = b
End Sub
_______________________________________________________________________________

If there is not a lot of data, you can also try this macro, it is smaller.
VBA Code:
Sub Check_two_columns_1()
  Dim i As Long, j As Long
  
  With Sheets("Data Set")
    For i = 2 To .Range("A" & Rows.Count).End(3).Row
      For j = 2 To .Cells(1, Columns.Count).End(1).Column Step 2
        If .Cells(i, j) <> "" Then
          Sheets("Result").Range("A" & Rows.Count).End(3)(2).Resize(1, 3).Value = _
          Array(.Cells(1, j), .Cells(i, j), .Cells(i, j + 1))
        End If
      Next j
    Next i
  End With
End Sub
 
Last edited:
Upvote 0
Hi Danteamor,

Thanks for the quick reply. What if I have one more column added in the data set.

1594763941590.png


Thank,
Kal
 
Upvote 0
What is the result according to your new example.
 
Upvote 0
Same Result as before only change is dataset has additional column in btw .
 
Upvote 0
Yes .. Same result as below. Still I need the result from same Column as I mentioned first but the data set changed with additional columns. I was not sure what changes to be done to skip the column and get desired result
 
Upvote 0
Try this
VBA Code:
Sub Check_two_columns_1()
  Dim i As Long, j As Long
  
  With Sheets("Data Set")
    For i = 2 To .Range("A" & Rows.Count).End(3).Row
      For j = 3 To .Cells(1, Columns.Count).End(1).Column Step 3
        If .Cells(i, j) <> "" Then
          Sheets("Result").Range("A" & Rows.Count).End(3)(2).Resize(1, 3).Value = _
          Array(.Cells(1, j), .Cells(i, j), .Cells(i, j + 1))
        End If
      Next j
    Next i
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,851
Messages
6,127,291
Members
449,374
Latest member
analystvar

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