Macro Correction

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Macro Correction

Post by zyxw1234 »

Code: Select all

Sub STEP6()
    Dim Wb1 As Workbook
    Dim Wb2 As Workbook
    Dim wb3 As Workbook
    Dim Ws1 As Worksheet
    Dim Ws2 As Worksheet
    Dim ws3 As Worksheet
    Dim strPath As String
    Dim r As Long
    Dim m As Long
    Dim rng As Range
    Dim n As Long
    Application.ScreenUpdating = False
    Set Wb1 = Workbooks.Open(ThisWorkbook.Path & "1.xls")
    Set Ws1 = Wb1.Worksheets(1)
    m = Ws1.Range("H" & Ws1.Rows.Count).End(xlUp).Row
    strPath = ThisWorkbook.Path & ""
    Set Wb2 = Workbooks.Open(strPath & "OrderFormat.xlsx")
    Set Ws2 = Wb2.Worksheets(1)
    Ws2.Range("A1:A4").TextToColumns DataType:=xlDelimited, Tab:=True, _
    SemiColon:=False, Comma:=False, Space:=False, Other:=False, _
    ConsecutiveDelimiter:=False
    Set wb3 = Workbooks.Open(strPath & "BasketOrder..csv")
    Set ws3 = wb3.Worksheets(1)
    Set rng = ws3.Cells.Find(what:="*", searchorder:=xlByRows, SearchDirection:=xlPrevious)
    If rng Is Nothing Then
        n = 1
    Else
        n = rng.Row + 1
    End If
    For r = 2 To m
        If Ws1.Range("H" & r).Value > Ws1.Range("D" & r).Value Then
            Ws2.Range("A1").EntireRow.Copy Destination:=ws3.Range("A" & n)
            n = n + 1
        ElseIf Ws1.Range("H" & r).Value < Ws1.Range("D" & r).Value Then
            Ws2.Range("A3").EntireRow.Copy Destination:=ws3.Range("A" & n)
            n = n + 1
        End If
    Next r
    Application.DisplayAlerts = False
    Wb1.Close SaveChanges:=False
    Wb2.Close SaveChanges:=False
    wb3.SaveAs FileName:=strPath & "BasketOrder..csv", FileFormat:=xlCSV
    wb3.Close SaveChanges:=False
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

I replaced the BasketOrder..csv with basketorder.xlsx so i need changes according to the same
So plz help me for the same
https://www.excelfox.com/forum/showthre ... Correction(i briefly mentioned the details in excelfox, If needed then plz let me know i will explain the same here too...)

User avatar
Leif
Administrator
Posts: 7209
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: Macro Correction

Post by Leif »

zyxw1234 wrote:
20 Jul 2020, 14:55

I replaced the BasketOrder..csv with basketorder.xlsx so i need changes according to the same
Have you tried replacing BasketOrder..csv with basketorder.xlsx in your code above?

** Please try and use a more descriptive and unique subject with each of your new threads - it is extremely difficult to know which is which if you simply call them all "Macro Correction"
Leif

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: Macro Correction

Post by zyxw1234 »

Sir only replacing the BasketOrder..csv with basketorder.xlsx will not work
Bcoz this is not a .csv file
so we have to think about these lines which are mentioned below , what we have to do with them that u will let me know bcoz u have a knowledge so thats y i asked the question looking for the perfect solution

Code: Select all

wb3.SaveAs FileName:=strPath & "BasketOrder..csv", FileFormat:=xlCSV

Code: Select all

Ws2.Range("A1:A4").TextToColumns DataType:=xlDelimited, Tab:=True, _
    SemiColon:=False, Comma:=False, Space:=False, Other:=False, _

Only replacing the BasketOrder..csv with basketorder.xlsx will not work & if its working also (then we don't need these lines bco'z we are not working with .csv files)

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Macro Correction

Post by HansV »

In the SaveAs line, you should use basketorder.xlsx as file name, and either omit the file format (it is not needed), or change xlCSV to xlOpenXMLWorkbook

You don't have to do anything about the TextToColumns line, it refers to another workbook.
Best wishes,
Hans

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: Macro Correction

Post by zyxw1234 »

Thnx Alot HansV Sir for helping me in solving this Problem
Problem Solved
Have a Awesome Day

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: Macro Correction

Post by zyxw1234 »

** Please try and use a more descriptive and unique subject with each of your new threads - it is extremely difficult to know which is which if you simply call them all "Macro Correction"


I will keep in mind from now, while posting any problems