Trying to omit the first row of excel and creating csv of sheet 2 using command button. pls help me with the code.

Isha Agg

New Member
Joined
Feb 4, 2018
Messages
3
Code:
Private Sub CommandButton1_Click()


Dim xWs As Worksheet
Dim xcsvFile As String
Dim rCell As Range
Dim rRow As Range
lFnum As Long
Dim rowCount As Long

For Each xWs In Application.ActiveWorkbook.Worksheets

For Each rRow In ActiveWorkbook.UsedRange.Rows
If rowCount > 1 Then
For Each rCell In rRow.Cells
xcsvFile = xcsvFile & rCell.Text & ";"
Next rCell
xcsvFile = Left(xcsvFile, Len(xcsvFile) - 1)
Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=lFnum"]#lFnum[/URL] , xcsvFile
MsgBox rRow.Row & vbCrLf & xcsvFile

xcsvFile = CurDir & "" & xWs.Name & ".csv"
Application.ActiveWorkbook.SaveAs Filename:=xcsvFile, _
FileFormat:=xlCSV, CreateBackup:=False
Application.ActiveWorkbook.Saved = True
Application.ActiveWorkbook.Close

End If
rowCount = rowCount + 1
Next rRow





End Sub


This is giving compile error. statement invalid outside Type block
 
Last edited by a moderator:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi

sorry if your worksheet contains:
. A B
1 1AA 1BB
2 2AA 2BB
3 3AA 3BB
4 4AA 4BB

what do you want the CSV file to contain?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

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