Macro Correction

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

Macro Correction

Post by zyxw1234 »

Code: Select all

Sub STEP7()
    Dim Wb1 As Workbook
    Dim wb3 As Workbook
    Dim Ws1 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("B" & Ws1.Rows.Count).End(xlUp).Row
    strPath = ThisWorkbook.Path & ""
    Set wb3 = Workbooks.Open(strPath & "BasketOrder..csv")
    Set ws3 = wb3.Worksheets(1)
    Set rng = ws3.Range("C:C").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
        ws3.Range("C" & n).Value = Ws1.Range("B" & r).Value
        n = n + 1
    Next r
    Application.DisplayAlerts = False
    wb3.SaveAs FileName:=strPath & "BasketOrder..csv", FileFormat:=xlCSV
    wb3.Close SaveChanges:=False
    Wb1.Close SaveChanges:=False
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

I have this macro which is working perfect but i converted the basketorder..csv to basketorder.xlsx so i need the modification according to that


https://excelfox.com/forum/showthread.p ... Correction

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

Re: Macro Correction

Post by Leif »

Is this the same question as your other thread with the subject "Macro Correction"?
Leif

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

Re: Macro Correction

Post by zyxw1234 »

No Sir every problem is different

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

Re: Macro Correction

Post by HansV »

It *is* the same question, even though the macro has a different name!
Best wishes,
Hans

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

Re: Macro Correction

Post by zyxw1234 »

Ok Now I got it but both has something different, I understood
I will let u know HansV Sir
Plz gove me some time

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

Re: Macro Correction

Post by zyxw1234 »

Code: Select all

Sub STEP7()
    Dim Wb1 As Workbook
    Dim wb3 As Workbook
    Dim Ws1 As Worksheet
    Dim ws3 As Worksheet
    Dim r As Long
    Dim m As Long
    Dim rng As Range
    Dim n As Long
    Application.ScreenUpdating = False
    Set Wb1 = Workbooks.Open("C:UsersWolfieeeStyleDesktop1.xls")
    Set Ws1 = Wb1.Worksheets(1)
    m = Ws1.Range("B" & Ws1.Rows.Count).End(xlUp).Row
    Set wb3 = Workbooks.Open("C:UsersWolfieeeStyleDesktopBasketOrder.xlsx")
    Set ws3 = wb3.Worksheets(1)
    Set rng = ws3.Range("C:C").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
        ws3.Range("C" & n).Value = Ws1.Range("B" & r).Value
        n = n + 1
    Next r
    Application.DisplayAlerts = False
    wb3.Close SaveChanges:=True
    Wb1.Close SaveChanges:=False
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

I am using this getting perfect output
Any more changes then plz let me know Sir
Thnx Alot HansV Sir & Leif Sir for helping me in solving this problem Sir
Have a Awesome Day
Last edited by zyxw1234 on 22 Jul 2020, 04:58, edited 1 time in total.

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

Re: Macro Correction

Post by HansV »

You can replace the two lines

Code: Select all

    wb3.Save
    wb3.Close SaveChanges:=False
with just one line:

Code: Select all

    wb3.Close SaveChanges:=True
Best wishes,
Hans

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

Re: Macro Correction

Post by zyxw1234 »

I changed the same
Thnx Alot HansV Sir for helping me in solving this Problem
Have a Great Day