Hi,
I have written below code for extracting data from cells and exporting to notepad. I have around 2 lak rows and 4 columns. So it takes so much of time to get executed.
So is there any easy time saving way, in which we could extract data and export it to textpad
Sub exporting()
Dim wsheet As Variant
Dim filename As String
Dim openfilename As String
Dim Filenum As Integer
Dim shRead As Worksheet
Dim FN As Integer
Dim eventname As String
Set shRead = ThisWorkbook.Worksheets("Sheet2")
eventname = Range("N4")
Dim lastRow As Long, lastCol As Long
' Get the last cell with data in column A
lastRow = shRead.Cells(shRead.Rows.Count, 11).End(xlUp).row
' Get the last cell with data in row 1
lastCol = shRead.Cells(8, shRead.Columns.Count).End(xlToLeft).Column
openfilename = "C:\Users\HP\Desktop\New folder\New folder\"
For i = 11 To lastCol
wsheet = ActiveSheet.Cells(8, i).Value
filename = wsheet
filename = eventname & "_" & filename & ".txt"
filename = openfilename & filename
For j = 9 To lastRow
mystring = mystring & vbNewLine & Cells(j, i)
FN = FreeFile
Open filename For Output As #FN
Print #FN, mystring
Close #FN
Next j
mystring = ""
Next i
End Sub
I have written below code for extracting data from cells and exporting to notepad. I have around 2 lak rows and 4 columns. So it takes so much of time to get executed.
So is there any easy time saving way, in which we could extract data and export it to textpad
Sub exporting()
Dim wsheet As Variant
Dim filename As String
Dim openfilename As String
Dim Filenum As Integer
Dim shRead As Worksheet
Dim FN As Integer
Dim eventname As String
Set shRead = ThisWorkbook.Worksheets("Sheet2")
eventname = Range("N4")
Dim lastRow As Long, lastCol As Long
' Get the last cell with data in column A
lastRow = shRead.Cells(shRead.Rows.Count, 11).End(xlUp).row
' Get the last cell with data in row 1
lastCol = shRead.Cells(8, shRead.Columns.Count).End(xlToLeft).Column
openfilename = "C:\Users\HP\Desktop\New folder\New folder\"
For i = 11 To lastCol
wsheet = ActiveSheet.Cells(8, i).Value
filename = wsheet
filename = eventname & "_" & filename & ".txt"
filename = openfilename & filename
For j = 9 To lastRow
mystring = mystring & vbNewLine & Cells(j, i)
FN = FreeFile
Open filename For Output As #FN
Print #FN, mystring
Close #FN
Next j
mystring = ""
Next i
End Sub