My scenario is that
How to print Unique values one by one in text file from column in excel using vba and also show value in msgbox one by one using vba Please give me a suggestion
thanks in Advance
My scenario is that
How to print Unique values one by one in text file from column in excel using vba and also show value in msgbox one by one using vba Please give me a suggestion
thanks in Advance
here's the "msgbox" part:
Sub main()
Dim cell As Range
For Each cell In Columns(1).SpecialCells(xlCellTypeConstants, xlTextValues) 'change column index to suit your need
If WorksheetFunction.CountIf(Range(Cells(1, cell.Column), cell), cell.Value) < 2 Then MsgBox cell.Value
Next
End Sub
I'll leave the "print to text file" part to you
Sub Unik()
Dim sh As Worksheet, sh2 As Worksheet, lr As Long, rng As Range
Set sh = Sheet1 'Edit sheet name
Dim strFile_Path As String
Dim i As Integer
Dim iCntr As Long
Close #1
Open "C:\Users\Downloads\ghds.txt" For Output As #1
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A2:A" & lr)
rng.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
sh.Rows(1).Hidden = True
For Each c In rng.SpecialCells(xlCellTypeVisible)
If Mystr = "" Then
Mystr = c.Value
Else
Mystr = Mystr & ", " & c.Value
Print #1, c.Value
End If
Next
Close #1
End Sub