VBA Macro Help!

chandler1983

New Member
Joined
Jan 5, 2014
Messages
10
HI,

I am having a hard time putting something together.

What I need is to be able to copy cells a3 - to I23, copy them into a new excel file, then without prompts save the file as c:\newFiles.csv and overwrite (even if the file exists with no prompts)

I have the first portion, however can't seem to find the last part to save properly.

Sub TRIM()
Dim wsOld As Worksheet
Dim wsNew As Worksheet

Set wsOld = ActiveSheet
Set wsNew = Workbooks.Add(xlWorksheet).Sheets(1)

wsOld.Range("A3:A23").Copy wsNew.Range("A:A")
wsOld.Range("B3:B23").Copy wsNew.Range("B:B")
wsOld.Range("C3:C23").Copy wsNew.Range("C:C")
wsOld.Range("D3:D23").Copy wsNew.Range("D:D")
wsOld.Range("E3:E23").Copy wsNew.Range("E:E")
wsOld.Range("F3:F23").Copy wsNew.Range("F:F")
wsOld.Range("G3:G23").Copy wsNew.Range("G:G")
wsOld.Range("H3:H23").Copy wsNew.Range("H:H")
wsOld.Range("I3:I23").Copy wsNew.Range("I:I")

End Sub


Am I able to do this with one button or does this have to be a 2-step process?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How about
Code:
Sub TRIM()
   Dim wsOld As Worksheet
   Dim wsNew As Worksheet
   
   Set wsOld = ActiveSheet
   Set wsNew = Workbooks.Add(xlWorksheet).Sheets(1)
   
   wsOld.Range("A3:I23").Copy wsNew.Range("A1")
   Application.DisplayAlerts = False
   With ActiveWorkbook
      .SaveAs fileName:= "C:\Newfile.csv", FileFormat:=xlCSV
      .Close
   End With
   Application.DisplayAlerts = True

End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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