Hi Everyone!
I found below code online and would like to tweak it to do the following:
Column A has multiple equal values and column B have different values
[ul][li]I would like to have a code that will see the data on column A (which has multiple equal value)[/li][/ul]
[ul][li]Find the range of equal value then create a notepad file with the name of the value found on column A (for example column A row 1-10 have same value name = AACE001N, then notepad file name will be AACE001N)[/li][/ul]
[ul][li]Then copy data range (which belongs to all rows related to column A AACE001N) from column B into the created Notepad file that was created and named AACE001N[/li][/ul]
[ul][li]Then proceed finding more new value from column A and continue creating notepad files and copying the data from column B which corresponds to value from column A[/li][/ul]
I Am attaching the file
Below the code I have now but what it does now is to created column A and B header name as a notepad files and copy data into the notepad:
Sub ExportToNotepad()
Dim wsData As Variant
Dim myFileName As String
Dim FN As Integer
Dim p As Integer, q As Integer
Dim path As String
Dim myString As String
Dim lastrow As Long, lastcolumn As Long
lastrow = Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
path = "C:\AWARDS\Notepad\"
For p = 1 To lastcolumn
wsData = ActiveSheet.Cells(1, p).Value
If wsData = "" Then Exit Sub
myFileName = wsData
myFileName = myFileName & ".txt"
myFileName = path & myFileName
'MsgBox myFileName
For q = 2 To lastrow
myString = myString & vbCrLf & Cells(q, p)
FN = FreeFile
Open myFileName For Output As #FN
Print #FN, myString
Close #FN
Next q
myString = ""
Next p
End Sub
I found below code online and would like to tweak it to do the following:
Column A has multiple equal values and column B have different values
[ul][li]I would like to have a code that will see the data on column A (which has multiple equal value)[/li][/ul]
[ul][li]Find the range of equal value then create a notepad file with the name of the value found on column A (for example column A row 1-10 have same value name = AACE001N, then notepad file name will be AACE001N)[/li][/ul]
[ul][li]Then copy data range (which belongs to all rows related to column A AACE001N) from column B into the created Notepad file that was created and named AACE001N[/li][/ul]
[ul][li]Then proceed finding more new value from column A and continue creating notepad files and copying the data from column B which corresponds to value from column A[/li][/ul]
I Am attaching the file
Below the code I have now but what it does now is to created column A and B header name as a notepad files and copy data into the notepad:
Sub ExportToNotepad()
Dim wsData As Variant
Dim myFileName As String
Dim FN As Integer
Dim p As Integer, q As Integer
Dim path As String
Dim myString As String
Dim lastrow As Long, lastcolumn As Long
lastrow = Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
path = "C:\AWARDS\Notepad\"
For p = 1 To lastcolumn
wsData = ActiveSheet.Cells(1, p).Value
If wsData = "" Then Exit Sub
myFileName = wsData
myFileName = myFileName & ".txt"
myFileName = path & myFileName
'MsgBox myFileName
For q = 2 To lastrow
myString = myString & vbCrLf & Cells(q, p)
FN = FreeFile
Open myFileName For Output As #FN
Print #FN, myString
Close #FN
Next q
myString = ""
Next p
End Sub