Filter result from two columns

Vishaal

Well-known Member
Joined
Mar 16, 2019
Messages
534
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. Web
HI, we want to filter data from two column to one

BarcSecond
SQ352
SQ353
SQ354
SQ354 - 1
SQ353
SQ354
SQ354 - 2


required result

Result
SQ352
SQ353
SQ354
SQ354 - 1
SQ353
SQ354
SQ354 - 2


help please
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Probably a dozen ways to do this, here's just one. You haven't indicated the location of the "Result" column, so the option below puts the output to column D. Change the sheet name to suit.

VBA Code:
Option Explicit
Sub Vishaal()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")    '<~~ *** Change to actual sheet name ***
    
    Dim a, b, i As Long, j As Long
    a = ws.Range("A2:B" & Range("A:B").Find("*", , xlFormulas, , xlByRows, xlPrevious).Row)
    ReDim b(1 To UBound(a, 1), 1 To 1)
    j = 1
    For i = 1 To UBound(a, 1)
        If a(i, 1) = "" And a(i, 2) = "" Then GoTo Skip
        If a(i, 1) = "" Then
            b(j, 1) = a(i, 2): j = j + 1
        Else
            b(j, 1) = a(i, 1): j = j + 1
        End If
Skip:
    Next i
    ws.Range("D2").Resize(UBound(b, 1)).Value = b
End Sub

Result after running the code:
Book1
ABCD
1BarcSecondResult
2SQ352
3SQ353
4SQ352SQ354
5SQ353SQ345 - 1
6SQ354SQ353
7SQ345 - 1SQ354
8SQ353SQ345 - 2
9SQ354
10SQ345 - 2
11
Sheet1
 
Upvote 0
Solution
thanks kevin9999, its working,

its my mistake, i required a formula instead of vba, can you please share the excel formula
 
Upvote 0
Are you looking for this, C2 "=IF(ISBLANK(A2),B2,A2)"
1684554573190.png
 
Upvote 0
thanks Sam_D_Ben

But you have removed all the blank rows from Column A and B, and we have the data where there are many blank rows

Result which you have provided is good, kindly check again please

Thanks
 
Upvote 0

Forum statistics

Threads
1,216,747
Messages
6,132,486
Members
449,729
Latest member
davelevnt

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