+ Reply to Thread
Results 1 to 27 of 27

Excel 2013 keep crashing when i run macro

Hybrid View

  1. #1
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Excel 2013 keep crashing when i run macro

    This is example of what it could look like
    i dont know what your sheet name is called for your vlookup
    edit sheet1 to whatever your sheet name is on the MISSINGUSERNAMEDEPT file

    i also assumed C1:C5 for your vlookup as i dont know which column your starting from or ending
    change this to suit your needs
    C1:C5 = A:E


    Private Sub Missing_UserName_Dept()
    
        ' Update User Name and Dept from Missing User name & dept xlsx file
    
        Dim MaxRowNum, RowNum As Long
        
        With Application
            .ScreenUpdating = False
            .Calculation = xlManual
            
        End With
        
        Sheets("Simpat").Select
        'Counting number of rows / Find the max number of row
        MaxRowNum = 1
            
        Do While Cells(MaxRowNum, 2) <> "" Or Cells(MaxRowNum + 1, 2) <> ""
            MaxRowNum = MaxRowNum + 1
        Loop
        
        'Find the row with the USERNAME & DEPT - "NOT INDICATED" and use a vlookup Function
    
        RowNum = 1
        
        For RowNum = 1 To MaxRowNum
        
            If UCase(Cells(RowNum, 16)) Like "*NOT INDICATED*" Or UCase(Cells(RowNum, 17)) Like "*NOT INDICATED*" Then
            
                'Vlookup User Name from the file MISSINGUSERNAMEDEPT.xlsx
                Range("P" & RowNum).FormulaR1C1 = "= VLOOKUP(RC[-3],[MISSINGUSERNAMEDEPT.xlsx]Sheet1!C1:C5,2,0)"
                
                'Vlookup Dept from the file MISSINGUSERNAMEDEPT.xlsx
                
                Range("Q" & RowNum).FormulaR1C1 = "= VLOOKUP(RC[-4],[MISSINGUSERNAMEDEPT.xlsx]Sheet1!C1:C5,3,0)"
            
                Range(Cells(RowNum, "P"), Cells(RowNum, "Q")).Select
                Selection.Copy
                Selection.PasteSpecial Paste:=xlPasteValues
                
            
            End If
        Next
        
        With Application
            .ScreenUpdating = True
            .Calculation = xlCalculationAutomatic
            
        End With
        
    End Sub
    i assume your maxrownum is working correctly....
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  2. #2
    Registered User
    Join Date
    07-01-2015
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    66

    Re: Excel 2013 keep crashing when i run macro

    Quote Originally Posted by humdingaling View Post
    This is example of what it could look like
    i dont know what your sheet name is called for your vlookup
    edit sheet1 to whatever your sheet name is on the MISSINGUSERNAMEDEPT file

    i also assumed C1:C5 for your vlookup as i dont know which column your starting from or ending
    change this to suit your needs
    C1:C5 = A:E


    Private Sub Missing_UserName_Dept()
    
        ' Update User Name and Dept from Missing User name & dept xlsx file
    
        Dim MaxRowNum, RowNum As Long
        
        With Application
            .ScreenUpdating = False
            .Calculation = xlManual
            
        End With
        
        Sheets("Simpat").Select
        'Counting number of rows / Find the max number of row
        MaxRowNum = 1
            
        Do While Cells(MaxRowNum, 2) <> "" Or Cells(MaxRowNum + 1, 2) <> ""
            MaxRowNum = MaxRowNum + 1
        Loop
        
        'Find the row with the USERNAME & DEPT - "NOT INDICATED" and use a vlookup Function
    
        RowNum = 1
        
        For RowNum = 1 To MaxRowNum
        
            If UCase(Cells(RowNum, 16)) Like "*NOT INDICATED*" Or UCase(Cells(RowNum, 17)) Like "*NOT INDICATED*" Then
            
                'Vlookup User Name from the file MISSINGUSERNAMEDEPT.xlsx
                Range("P" & RowNum).FormulaR1C1 = "= VLOOKUP(RC[-3],[MISSINGUSERNAMEDEPT.xlsx]Sheet1!C1:C5,2,0)"
                
                'Vlookup Dept from the file MISSINGUSERNAMEDEPT.xlsx
                
                Range("Q" & RowNum).FormulaR1C1 = "= VLOOKUP(RC[-4],[MISSINGUSERNAMEDEPT.xlsx]Sheet1!C1:C5,3,0)"
            
                Range(Cells(RowNum, "P"), Cells(RowNum, "Q")).Select
                Selection.Copy
                Selection.PasteSpecial Paste:=xlPasteValues
                
            
            End If
        Next
        
        With Application
            .ScreenUpdating = True
            .Calculation = xlCalculationAutomatic
            
        End With
        
    End Sub
    i assume your maxrownum is working correctly....
    Yeah , the maxrownum is working correctly .
    Thank you so much It can work.
    Could i ask one more thing , Is it possible to replace "#N/A" to "NOT INDICATED" ?

+ 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. Custom cell formatting crashing Excel 2013
    By rpdhuk in forum Excel General
    Replies: 1
    Last Post: 06-23-2015, 12:29 PM
  2. VBA code causing memory leak. Crashing Excel 2013/64. Please help.
    By kabammi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-10-2015, 11:19 PM
  3. Macros crashing Excel 2013
    By Thor42 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-03-2015, 05:13 PM
  4. Excel 2013 Crashing on opening a XLSM file
    By Wongadob in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2014, 05:10 AM
  5. Replies: 3
    Last Post: 07-20-2014, 11:46 AM

Tags for this Thread

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