Ending at a dead cell

chandler1983

New Member
Joined
Jan 5, 2014
Messages
10
Greetings!

I am trying to have this Macro export a CSV, works great, however I need it to stop if there is a blank on the A. Can anyone help?

I tried the endXLUP Up, but no avail..

Sub Export()


Dim wsOld As Worksheet
Dim wsNew As Worksheet

Set wsOld = ActiveSheet
lastrow = Range("A2:U1029").End(xlUp).Row
Set wsNew = Workbooks.Add(xlWorksheet).Sheets(1)


wsOld.Range("A2" + CStr(lastrow)).Copy wsNew.Range("A1")


Application.DisplayAlerts = False
With ActiveWorkbook
.SaveAs Filename:="Z:\SBM\OUTPUT\cs_inv_line.csv", FileFormat:=xlCSV
.Close
End With
Application.DisplayAlerts = True


End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
Sub Export()
  With Range("A2", Cells(Cells(Rows.Count, "A").End(xlUp).Row, "U"))
    .Select
    Stop ' and take a look
    .ExportAsFixedFormat Type:=xlCSV, Filename:="Z:\SBM\OUTPUT\cs_inv_line.csv"
  End With
End Sub
 
Upvote 0
Code:
Sub Export()
  With Range("A2", Cells(Cells(Rows.Count, "A").End(xlUp).Row, "U"))
    .Select
    Stop ' and take a look
    .ExportAsFixedFormat Type:=xlCSV, Filename:="Z:\SBM\OUTPUT\cs_inv_line.csv"
  End With
End Sub

Hi,

Copy part works perfectly, however I get a run-tire error 5 on this line
.ExportAsFixedFormat Type:=xlCSV, Filename:="Z:\SBM\OUTPUT\cs_inv_line.csv"
 
Upvote 0

Forum statistics

Threads
1,216,523
Messages
6,131,171
Members
449,627
Latest member
ChrisNoMates

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