Object Required Error in VBA,

Sharda

New Member
Joined
Nov 19, 2017
Messages
15
Sub Split()


Dim wb As String
Dim ws As String


wb = ActiveWorkbook.Name
ws = ActiveSheet.Name


Vcolumn = InputBox("Please indicate which column (i.e. A,B,C,...), you would like to split by", "Column selection")


Columns(Vcolumn).Copy
Sheets.Add
ActiveSheet.Name = "_Summary"
Range("A1").PasteSpecial
Columns("A").RemoveDuplicates Columns:=1, Header:=x1Yes


vCounter = Range("B" & Row.Count).End(xlUp).Row


For i = 2 To vCounter
vfilter = Sheets("_Summary").Cells(i, 1)
Sheets(ws).Activate
ActiveSheet.Columns.AutoFilter field:=Columns(Vcolumn).Column, Criteria1:=vfilter
Cells.Copy
Workbooks.Add
Range("A1").PasteSpecial
If vfilter <> "" Then
ActiveWorkbook.SaveAs ThiWorkbook.Path & "\Split Result" & vfilter
Else
ActiveWorkbook.SaveAs ThisWorkbook.Path & "Split Result\_Empty"
End If
ActiveWorkbook.Close
Workbooks(wb).Activate
Next i


Sheets("_Summary").Delete


End Sub
 
Try this
Code:
Sub Split()

    Dim SrcSht As Worksheet
    Dim TmpSht As Worksheet
    Dim vCounter As Long
    Dim vColumn As String
    Dim vFilter As String
    Dim i As Long
    
    Set SrcSht = ActiveSheet
    vColumn = InputBox("Please indicate which column (i.e. A,B,C,...), you would like to split by", "Column selection")
    
    Sheets.Add.Name = "_Summary"
    Set TmpSht = ActiveSheet
    
    SrcSht.Columns(vColumn).copy TmpSht.Range("A1")
    TmpSht.Range("A1").Delete xlUp
    TmpSht.Columns("A").RemoveDuplicates Columns:=1, Header:=xlYes
    vCounter = TmpSht.Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 2 To vCounter
        vFilter = TmpSht.Range("A" & i)
        SrcSht.Rows(2).AutoFilter field:=Columns(vColumn).Column, Criteria1:=vFilter
        Workbooks.Add
        SrcSht.Range("A1").CurrentRegion.SpecialCells(xlVisible).copy ActiveWorkbook.Sheets(1).Range("A1")
        ActiveWorkbook.SaveAs fileName:=ThisWorkbook.path & "\Split Result" & vFilter, FileFormat:=6
        ActiveWorkbook.Close False
    Next i
    TmpSht.Delete

End Sub
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Thank you so much Fluff it worked :)
Thanks Stiuart for your efforts too!
God Bless You Both!
 
Last edited:
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
One last thing Now I need to convert these CSV files to TXT, I succeeded with below code.
However need help with two things:
1) This code should be applied to all CVS files in given path. Because It gave result on only given number.
2) I want on TXT top line as: LEDES98BI V2[] instead of LEDES98BI V2[]|||||||||||||||||||||||||||||||||||||||||||||||||||

Code:
Sub csv2mat()
Dim Filename As String
Dim Filenamenew As String
Dim str As String
'Change the path to the Files and and create a txt file
Filename = "C:\Users\Rimpi Pihuja\Desktop\New folder (2)\New folder\New folder\1040448.csv"
Filenamenew = "C:\Users\Rimpi Pihuja\Desktop\New folder (2)\New folder\New folder\1040448.txt"
Open Filenamenew For Output As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=2]#2[/URL] 
Open Filename For Input As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
Do While Not EOF(1)
    Line Input [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , str
    str = Replace(str, ",", "|")
    Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=2]#2[/URL] , str
Loop
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=2]#2[/URL] 
End Sub
 
Upvote 0
As this is a new question, I'd recommend you start a new thread.
Especially as I cannot help with this.:(
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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