Delete rows from another tab based on data in cells and keep formula

ScottGFrustrated

New Member
Joined
Oct 12, 2023
Messages
8
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
I have a simple workbook that I use to enter data and I have macros that send the data to another workbook. The workbook I am sending to must be CSV and the problem I am having is if I only have data in my top row, when it transfers to new workbook, I am getting commas in rows below that. Currently, to bypass this issue, I have to open the CSV workbook, manually select the rows below the data that I need and delete them every time I transfer. I want to be able to click my "Export Data" button and transfer data to the new workbook and ALSO delete any row that contains "<DO NOT CHANGE" in column B.

The data I enter in Worksheet 'Data' automatically transposes to Worksheet 2 'Transfer' and that is where the information for the transfer comes from. I don't want to delete from Worksheet 2 because I have formulas there.

Workbook I enter data in - SFC Transfers
Worksheet it is on - Data
Worksheet 2 - Transfer
Workbook it transfers to - Manualtransfers.csv

My current Macro:
Public Sub XPORTCSV()

Dim wbkExport As Workbook
Dim shtToExport As Worksheet
Dim FPath As String
Dim answer As Integer
Dim RowCount As Long

RowCount = Worksheets("System Settings").Range("A87").Value


Sheets("Transfer").Select
Range("A1:J7").Select
Selection.Copy


FPath = Sheets("System Settings").Range("C2").Text

Set shtToExport = ThisWorkbook.Worksheets("Transfer")
Set wbkExport = Application.Workbooks.Add
shtToExport.Copy Before:=wbkExport.Worksheets(wbkExport.Worksheets.Count)
Application.DisplayAlerts = False
wbkExport.SaveAs Filename:=FPath & "\ManualTransfers", FileFormat:=xlCSV
Application.DisplayAlerts = True
wbkExport.Close SaveChanges:=False




End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I never save an Workbook as a csv, I always export them to a csv. See Below.

VBA Code:
Sub Export()
Dim ws As Worksheet

Set ws = ThisWorkbook.Worksheets("Transfer")

fpath = Sheets("System Settings").Range("C2").Text
fName =  "\" & ws.Name & ".csv"

delim = ","
lc = ws.Cells(1, Columns.Count).End(xlToLeft).Column
For r = 2 To ws.Cells(Rows.Count, "A").End(xlUp).Row 'loop thru every row

For C = 1 To lc 'loop thru every column

    Data = Data & ws.Cells(r, C) & delim

Next C
Data = Data & vbCrLf

Next r



Open fpath & fName For Output As #1
Print #1, Data
Close #1
Data = ""

End Sub

hth,
-Ross
 
Upvote 0
Solution

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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