+ Reply to Thread
Results 1 to 9 of 9

Need help converting Excel 2003 code to work in Excel 2013

Hybrid View

rls231 Need help converting Excel... 08-09-2014, 11:43 AM
patel45 Re: Need help converting... 08-09-2014, 12:44 PM
rls231 Re: Need help converting... 08-09-2014, 01:30 PM
HaHoBe Re: Need help converting... 08-09-2014, 01:37 PM
rls231 Re: Need help converting... 08-10-2014, 08:26 AM
patel45 Re: Need help converting... 08-09-2014, 01:49 PM
rls231 Re: Need help converting... 08-10-2014, 08:27 AM
HaHoBe Re: Need help converting... 08-10-2014, 09:22 AM
rls231 Re: Need help converting... 08-28-2014, 01:02 AM
  1. #1
    Registered User
    Join Date
    01-14-2013
    Location
    United States
    MS-Off Ver
    2003 & 2010 - Excel, Word, PP, etc.
    Posts
    26

    Need help converting Excel 2003 code to work in Excel 2013

    Hello,

    I have not been able to figure out why this vba doesn't work. I have been able to get the rest of the workbook functional. Here is what I would like to accomplish:

    Upon entering a date on any worksheet (this file has a tab "140801" that it should work on) in J12, the macro "Paid" runs. Here is what "Paid" should do:

    Unhide sheet "INDEX"
    Search for the number in cell G11
    Select the row in which G11 appears
    Copy the row, paste values in same place
    Hide sheet "INDEX"
    Go back to sheet "140801" (original active sheet, name changes)

    Select range B2:M60
    Copy
    Paste values

    Open a different workbook "Paid Invoices"
    Go back to first workbook
    Move active sheet (do not create copy) to "Paid Invoices"
    Save and close "Paid Invoice"
    Go back to first workbook sheet "MAIN"

    Here is the code that I have (worked in 2003)

    Sub paid()
    '
    ' paid Macro
    ' Macro recorded 8/15/2013 by R
    '
    
    Dim FindMe As Long
    Dim lastrowIndex As Long
    Dim wsSummPaid As Worksheet
    
    
    Range(ActiveCell.Address).Name = "StartCell"
        FindMe = Range("G11")
        Sheets("INDEX").Visible = True
        Sheets("INDEX").Select
        Cells.Find(What:=FindMe, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
            ActiveCell.EntireRow.Select
           Application.CutCopyMode = False
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
         Sheets("INDEX").Visible = False
             Application.GoTo "StartCell"
        Range("B2:J30").Select
        Application.CutCopyMode = False
          Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues
    Application.GoTo "StartCell"
       Workbooks.Open Filename:="C:\Users\Rita\Desktop\Paid Invoices.xls*", _
            UpdateLinks:=0
       Windows("CP INVOICES V.062314.xls").Activate
       ActiveSheet.Select
       Application.CutCopyMode = False
       Application.DisplayAlerts = False
       ActiveSheet.Move After:=Workbooks("Paid Invoices.xls*").Sheets("Summary")
    Set wsSummPaid = Sheets("Summary")
    lastrowIndex = wsSummPaid.Range("A" & Rows.Count).End(xlUp).Row
        
     With wsSummPaid
    .Range("A" & lastrowIndex + 1).FormulaR1C1 = FindMe
                .Range("B" & lastrowIndex + 1).FormulaR1C1 = "=INDIRECT(""'" & FindMe & "'!$J5"")"
                .Range("C" & lastrowIndex + 1).FormulaR1C1 = "=INDIRECT(""'" & FindMe & "'!$G29"")"
                .Range("D" & lastrowIndex + 1).FormulaR1C1 = "=INDIRECT(""'" & FindMe & "'!$B8"")"
                
    End With
    
    
    
        ActiveWorkbook.Save
       ActiveWorkbook.Close
       Sheets("MAIN").Select
        
    Application.DisplayAlerts = True
    End Sub
    Thanks for taking a look!!
    I attached the workbook as well.
    invoice test workbook.xlsm
    Paid Invoices.xlsm
    Last edited by rls231; 08-09-2014 at 01:28 PM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Need help converting Excel 2003 code to work in Excel 2013

    I need file Paid Invoices.xls for testing
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    01-14-2013
    Location
    United States
    MS-Off Ver
    2003 & 2010 - Excel, Word, PP, etc.
    Posts
    26

    Re: Need help converting Excel 2003 code to work in Excel 2013

    thanks - I attached to original post

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Need help converting Excel 2003 code to work in Excel 2013

    Hi, rls231,

    maybe the Debugger in Excel2013 doesn´t like the asterisk in
    "C:\Users\Rita\Desktop\Paid Invoices.xls*"
    Sub EF1030206()
    '
    ' paid Macro
    ' Macro recorded 8/15/2013 by R
    '
    
    Dim FindMe As Long
    Dim lngWriteTo As Long
    Dim wsSummPaid As Worksheet
    Dim rngFound As Range
    Dim wb As Workbook
    
    Range(ActiveCell.Address).Name = "StartCell"
    With Sheets("INDEX")
      .Visible = True
      Set rngFound = .Cells.Find(What:=CStr(Range("G11").Value), _
          LookIn:=xlValues, _
          LookAt:=xlPart, _
          SearchOrder:=xlByRows, _
          SearchDirection:=xlNext, _
          MatchCase:=False, _
          SearchFormat:=False)
      If Not rngFound Is Nothing Then
        With rngFound.EntireRow
          .Value = .Value
        End With
      End If
      .Visible = False
    End With
    
    If rngFound Is Nothing Then
      Exit Sub
    Else
      Set rngFound = Nothing
    End If
    
    With Range("B2:J30")
      .Value = .Value
    End With
    
    Application.GoTo "StartCell"
    Set wb = Workbooks.Open(Filename:="C:\Users\Rita\Desktop\Paid Invoices.xlsm", UpdateLinks:=0)
    
    Application.DisplayAlerts = False
    ThisWorkbook.ActiveSheet.Move After:=wb.Sheets("Summary")
    
    Set wsSummPaid = wb.Sheets("Summary")
    lngWriteTo = wsSummPaid.Range("A" & Rows.Count).End(xlUp).Row + 1
        
     With wsSummPaid
      .Range("A" & lngWriteTo).Value = Range("G11").Value
      .Range("B" & lngWriteTo).FormulaR1C1 = "=INDIRECT(""'" & Range("G11").Value & "'!$J5"")"
      .Range("C" & lngWriteTo).FormulaR1C1 = "=INDIRECT(""'" & Range("G11").Value & "'!$G29"")"
      .Range("D" & lngWriteTo).FormulaR1C1 = "=INDIRECT(""'" & Range("G11").Value & "'!$B8"")"
    End With
    
    wb.Close True
    Sheets("MAIN").Select
    Application.DisplayAlerts = True
    
    Set wsSummPaid = Nothing
    Set wb = Nothing
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Registered User
    Join Date
    01-14-2013
    Location
    United States
    MS-Off Ver
    2003 & 2010 - Excel, Word, PP, etc.
    Posts
    26

    Re: Need help converting Excel 2003 code to work in Excel 2013

    Thank you for your response. The code worked perfectly to move the sheet as indicated. However, it didn't get rid of the sheet in the VB project view and for some reason it errored out on code within the sheet. I read through the code and couldn't see where this would happen. Any ideas? Thanks!

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Need help converting Excel 2003 code to work in Excel 2013

    Sub paid()
    Dim FindMe As Long
    Dim lastrowIndex As Long
    Dim wsSummPaid As Worksheet
    
    Set wb = ThisWorkbook
    Range(ActiveCell.Address).Name = "StartCell"
        FindMe = Range("G11")
        Sheets("INDEX").Visible = True
        Sheets("INDEX").Select
        Cells.Find(What:=FindMe, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
            ActiveCell.EntireRow.Select
           Application.CutCopyMode = False
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
         Sheets("INDEX").Visible = False
             Application.GoTo "StartCell"
        Range("B2:J30").Select
        Application.CutCopyMode = False
          Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues
    Application.GoTo "StartCell"
       Set wb1 = Workbooks.Open(Filename:="C:\Users\Rita\Desktop\Paid Invoices.xlsm", _
            UpdateLinks:=0)
       Application.CutCopyMode = False
       Application.DisplayAlerts = False
       wb.Sheets("INDEX").Move After:=wb1.Sheets("Summary")
    Set wsSummPaid = wb1.Sheets("Summary")
    lastrowIndex = wsSummPaid.Range("A" & Rows.Count).End(xlUp).Row
        
     With wsSummPaid
    .Range("A" & lastrowIndex + 1).FormulaR1C1 = FindMe
                .Range("B" & lastrowIndex + 1).FormulaR1C1 = "=INDIRECT(""'" & FindMe & "'!$J5"")"
                .Range("C" & lastrowIndex + 1).FormulaR1C1 = "=INDIRECT(""'" & FindMe & "'!$G29"")"
                .Range("D" & lastrowIndex + 1).FormulaR1C1 = "=INDIRECT(""'" & FindMe & "'!$B8"")"
                
    End With
    wb1.Save
    wb1.Close
    Sheets("MAIN").Select
    Application.DisplayAlerts = True
    End Sub

  7. #7
    Registered User
    Join Date
    01-14-2013
    Location
    United States
    MS-Off Ver
    2003 & 2010 - Excel, Word, PP, etc.
    Posts
    26

    Re: Need help converting Excel 2003 code to work in Excel 2013

    Thanks! I couldn't quite get this to work. I found Holger's code to work, but with one error (see my response). I am not sure what in this code didn't work. Really appreciate your time!!

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Need help converting Excel 2003 code to work in Excel 2013

    Hi, rls231,

    the code from my post isn´t working for the sheet intended (the moved one) but on the active sheet instead.

    You should try this altered code:
    Sub EF1030206_2()
    '
    ' paid Macro
    ' Macro recorded 8/15/2013 by R
    '
    
    Dim FindMe        As Long
    Dim lngWriteTo    As Long
    Dim wsSummPaid    As Worksheet
    Dim rngFound      As Range
    Dim wb            As Workbook
    Dim wsNewInv      As Worksheet 'will be used for teh moved sheet into the summary workbook
    
    Range(ActiveCell.Address).Name = "StartCell"
    With Sheets("INDEX")
      .Visible = True
      Set rngFound = .Cells.Find(What:=CStr(Range("G11").Value), _
          LookIn:=xlValues, _
          LookAt:=xlPart, _
          SearchOrder:=xlByRows, _
          SearchDirection:=xlNext, _
          MatchCase:=False, _
          SearchFormat:=False)
      If Not rngFound Is Nothing Then
        With rngFound.EntireRow
          .Value = .Value
        End With
      End If
      .Visible = False
    End With
    
    If rngFound Is Nothing Then
      Exit Sub
    Else
      Set rngFound = Nothing
    End If
    
    With Range("B2:J30")
      .Value = .Value
    End With
    
    Application.GoTo "StartCell"
    Set wb = Workbooks.Open(Filename:="C:\Users\Rita\Desktop\Paid Invoices.xlsm", UpdateLinks:=0)
    
    Application.DisplayAlerts = False
    ThisWorkbook.ActiveSheet.Move After:=wb.Sheets("Summary")
    'newly set here
    Set wsNewInv = wb.ActiveSheet
    
    Set wsSummPaid = wb.Sheets("Summary")
    lngWriteTo = wsSummPaid.Range("A" & Rows.Count).End(xlUp).Row + 1
        
    'I changed from placing a formula to writing values, a paid invoice should not change and be reflectd.
    'Please check the ranges of the origins to suit.
    With wsSummPaid
      .Range("A" & lngWriteTo).Value = wsNewInv.Range("G11").Value
      .Range("B" & lngWriteTo).Value = wsNewInv.Range("J12").Value
      .Range("C" & lngWriteTo).Value = wsNewInv.Range("G37").Value
      .Range("D" & lngWriteTo).Value = wsNewInv.Range("B15").Value
    End With
    
    wb.Close True
    Sheets("MAIN").Select
    Application.DisplayAlerts = True
    
    Set wsNewInv = Nothing
    Set wsSummPaid = Nothing
    Set wb = Nothing
    End Sub
    Looking at the codes in your workbook I wonder if the movement of the cursor should trigger an event to calculate (I would expect any choice being made to do so but I may be wrong on that).

    As the sheet will be copied over you should take precautions that the code won´t be run again in the collection workbook. One way would be to copy the worksheet into a new workbook, save as macrofree xlsx FileFormat, move the sheet from there with no code into the collection wb and delete the temp file. Or get the name of the workbook and exit the sub if it´s the summray/collection wb:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    Dim rngCell As Range
    
    'check the name of the workbook, if it´s the summary stop the code
    If ActiveSheet.Parent.Name = "Paid Invoices.xlsm" Then Exit Sub
    
    If Target.Address = "$J$12" And Range("$J$12").Value <> "" Then paid
    
    If Not Intersect(Target, Range("B27:B32")) Is Nothing Then
      Range("G27:G32").FormulaR1C1 = "=RC[-3]*RC[-2]"
      Range("G33") = "=SUM(G27:G32)"
      Range("G37") = "=SUM(G33+G35)"
    
      For Each rngCell In Range("B27:B32")
        Select Case rngCell
          Case "LABOR - FIRST HOUR"
            Range("D27") = 140
          Case "LABOR - REGULAR"
            Range("D27") = 110
          Case "LABOR - AFTER HOURS"
            Range("D27") = 175
          Case "LABOR - WEEKEND / HOLIDAY"
            Range("D27") = 225
        End Select
      Next rngCell
    End If
    
    If Not Intersect(Target, Range("$B$15:$D$18")) Is Nothing Then
      Select Case Range("$B$15")
        Case "MACY'S EXPENSE PAYABLE | MAINTENANCE OFFICE"
          Range("$D$14") = "JOB SITE"
          With Range("$D$15").Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                xlBetween, Formula1:="=Job_Site_Addresses"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = False
            .ShowError = False
          End With
    
          With Range("$D$16")
            .Formula = "=VLOOKUP($D$15,'Customer Data'!$U$3:$Z$68,2,FALSE)"
            .Value = .Value
          End With
    
          With Range("$D$17")
            .Formula = "=VLOOKUP($D$15,'Customer Data'!$U$3:$Z$68,6,FALSE)"
            .Value = .Value
          End With
        Case Else
          Range("$D$14:$D$19") = ""
     End Select
    End If
      
    End Sub
    Code is untested, I would have used the Change-event instead. But as this code is not part of the original post...

    Regarding the update on the project explorer: when starting your code by moving the cursor strange flickering on my project explorer appeared, one of the reasons I suggested to use a different event to raise the calculation or movement. If a worksheet won´t disappear from the project explorer please close Excel and start again. I´m sorry I don´t have any different answer to that by now.

    Ciao,
    Holger

  9. #9
    Registered User
    Join Date
    01-14-2013
    Location
    United States
    MS-Off Ver
    2003 & 2010 - Excel, Word, PP, etc.
    Posts
    26

    Re: Need help converting Excel 2003 code to work in Excel 2013

    I still have a few issues, but will start new thread. THANK you very much for all of what you provided.
    Last edited by rls231; 08-28-2014 at 08:35 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Code does not work after Excel 2013 Upgrade
    By amalejko in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2014, 01:56 PM
  2. Converting vba code in Excel XP to make it work in Excel 2010
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2014, 08:43 AM
  3. [SOLVED] Code to work in both Excel 2013 and 2003
    By 1eyedjack in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2014, 09:30 AM
  4. Code created in Excel 2010 does not work with Excel 2013
    By Steve@Rugby in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2014, 10:14 AM
  5. Converting Excel 2007 formula to work in Excel 2003
    By Fastd in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-13-2011, 07:44 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1