I want to do a combination in the scope excluding empty cells in the VBA Range area.

ted kim

New Member
Joined
Jul 1, 2022
Messages
4
Office Version
  1. 365
Platform
  1. MacOS
xDRg1, xDRg2, xDRg3 Ranges contain empty Cells. Can I do a combination other than this?

VBA Code:
Sub ListAllCombinations()
'Updateby Extendoffice
Dim xDRg1, xDRg2, xDRg3 As Range
Dim xRg  As Range
Dim xStr As String
Dim xFN1, xFN2, xFN3 As Integer
Dim xSV1, xSV2, xSV3 As String
Set xDRg1 = Range("a2", ActiveSheet.Range("a2").End(xlDown))  'First column data
Set xDRg2 = Range("b2", ActiveSheet.Range("b2").End(xlDown))   'Second column data
Set xDRg3 = Range("c2", ActiveSheet.Range("c2").End(xlDown))   'Third column data
xStr = "_"   'Separator
Set xRg = Range("E2")  'Output cell
For xFN1 = 1 To xDRg1.Count
    xSV1 = xDRg1.Item(xFN1).Text
    For xFN2 = 1 To xDRg2.Count
        xSV2 = xDRg2.Item(xFN2).Text
      For xFN3 = 1 To xDRg3.Count
        xSV3 = xDRg3.Item(xFN3).Text
        xRg.Value = xSV1 & xStr & xSV2 & xStr & xSV3
        Set xRg = xRg.Offset(1, 0)
       Next
    Next
Next
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
VBA Code:
Sub ListAllCombinations()
Dim i&, j&, k&, t&, lrA&, lrB&, lrC&, rng, arr(1 To 100000, 1 To 1)
lrA = Cells(Rows.Count, "A").End(xlUp).Row
lrB = Cells(Rows.Count, "B").End(xlUp).Row
lrC = Cells(Rows.Count, "C").End(xlUp).Row
For i = 2 To lrA
    For j = 2 To lrB
        For k = 2 To lrC
            If IsEmpty(Cells(i, "A")) Or IsEmpty(Cells(j, "B")) Or IsEmpty(Cells(k, "C")) Then
            Else
                t = t + 1
                arr(t, 1) = Cells(i, "A") & "_" & Cells(j, "B") & "_" & Cells(k, "C")
            End If
        Next
    Next
Next
Range("E2").Resize(t, 1).Value = arr
End Sub

Capture.JPG
 
Upvote 0
A value can exist in columns a and b, but an error occurs when column c does not have a value.
Can you supplement this?

I want to make the result value like column F

스크린샷 2022-07-01 오후 9.35.33.png
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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