Exporting data to a new xls workbook

Frank10

New Member
Joined
Nov 19, 2018
Messages
7
Hi,

I am trying to export data from an xlsm to a new xls.

But the problem is that it only copies the first row and I need a table to be copied.


My macro is this one:

Sub ExportarTXT()

Worksheets("Import").Activate
If Sheets("Import").Activate Then
Range("A1").Select
If ActiveCell = Empty Then GoTo salte
Open "c:\ZLibra.xls" For Output As 1
regresa:
Codigo = ActiveCell
Print #1 , Codigo
ActiveCell.Offset(1, 0).Select
If ActiveCell = Empty Then GoTo salte
GoTo regresa:

salte:
Close #1
End If
Worksheets("Import").Activate

End Sub


Thanks,
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
The code that you have here is writing the data to an ASCII text file, even though you are naming it .xls. This won't work.

Please describe the data you want to export. You called it a table, but the code is just writing data from column A. Can you give a more complete description of where/what the data is?
 
Upvote 0
Hi,

Thanks for the answer. This macro exports ok the first column.
I need to extend it till column "O".

The data is like this.

ASIENTOFECHACUENTACONCEPTOMONEDA DEBE HABER TIPOCOTIZACIONCENTROREFERENCIALOCALRUTTRIBUTOORIGEN
1542/1/20171155119Pago BPS2 994.93 - W-2.000.000.00ZetaLIBRA
1542/1/20171112101Pago BPS2 - 994.93W-2.000.000.00ZetaLIBRA
1552/1/20171155119Pago BPS1 646,789.00 - W0.000.000.00ZetaLIBRA

<colgroup><col><col><col><col><col><col span="2"><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
This assumes that you want to export the entire worksheet.
Code:
Sub ExportarTXT()


   Dim ExportWB As Workbook
   
   Set ExportWB = Workbooks.Add
   ThisWorkbook.Worksheets("Import").Cells.Copy ExportWB.Sheets(1).Range("A1")
   ExportWB.SaveAs FileName:="c:\ZLibra.xls", FileFormat:=xlExcel8
   
End Sub
 
Upvote 0
Stringjazzer,

Thanks a lot for the help. Sorry for not fully explain myself.

I need to export to that workbook in values not in formulas.
Also there are formulas at the end that show all the row in blank. So if I go Ctrl+shift+down it goes all down till that blank rows also.
I need to export only the ones that have values but not blank.

Sorry for the inconvenience.

Thanks again.
 
Upvote 0
This takes the values instead of formulas. In such a case blank cells become a non-issue.
Rich (BB code):
Sub ExportarTXT()




   Dim ExportWB As Workbook
   
   Set ExportWB = Workbooks.Add
   ThisWorkbook.Worksheets("Import").Cells.Copy
   ExportWB.Sheets(1).Range("A1").PasteSpecial xlPasteValues
   ExportWB.SaveAs Filename:="c:\ZLibra.xls", FileFormat:=xlExcel8
   
End Sub
 
Last edited:
Upvote 0
6StringJazzer,

Sorry one more thing.

What can I add to this macro for after exporting to the ZLibra.xls refresh cells from A1:P2000. For the date to apply format and blank cells being removed.

Thankss!! a lot
 
Upvote 0
This macro but then copying A1:P2000 and pasting like values, then refresh A1:P2000 cells.


Sub ExportarTXT()


Dim ExportWB As Workbook

Set ExportWB = Workbooks.Add
ThisWorkbook.Worksheets("Import").Cells.Copy ExportWB.Sheets(1).Range("A1")
ExportWB.SaveAs FileName:="c:\ZLibra.xls", FileFormat:=xlExcel8

End Sub



Im so bad explaining myslef. This is the last oneee
 
Upvote 0
"What can I add to this macro for after exporting to the ZLibra.xls refresh cells from A1:P2000. For the date to apply format and blank cells being removed."

I'm sorry but I have no idea what you mean by this.

The code you posted in post 9 is not the last version I provided. You should use the code in post 6.


 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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