+ Reply to Thread
Results 1 to 6 of 6

Runtime Error Type Mismatch

Hybrid View

hungryhobo Runtime Error Type Mismatch 05-08-2013, 05:02 PM
Norie Re: Runtime Error Type... 05-08-2013, 05:28 PM
hungryhobo Re: Runtime Error Type... 05-08-2013, 05:47 PM
Norie Re: Runtime Error Type... 05-08-2013, 06:07 PM
hungryhobo Re: Runtime Error Type... 05-08-2013, 06:21 PM
Norie Re: Runtime Error Type... 05-08-2013, 08:50 PM
  1. #1
    Registered User
    Join Date
    06-18-2012
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    19

    Runtime Error Type Mismatch

    For some reason this code works at home two test files, but when running at work I get this error. The macro loops through a list of sheet names in the macrobook and in the wb2 it should select all cells and copy paste as values, which doesn't happen because of this error. Then it deletes all sheets if the sheet name is not in the list in the macrobook. It does delete the sheets properly. Maybe the solution would be to add another code that loops through the remaining sheets and copy paste as values? Or does someone know what I'm doing wrong here.

    
    Sub NewWeek_4()
        Dim Macrobook As Workbook
        Dim wb2 As Workbook
        Dim rngCell As Range
        Dim macrosheet As Worksheet
        Dim ws2 As Worksheet
        
        Application.ScreenUpdating = False
        Set Macrobook = ActiveWorkbook
        Set macrosheet = Macrobook.ActiveSheet
        
         Set wb2 = Workbooks.Open(Filename:="O:\2\folder01\Analysis 0430.xlsx")
        For Each ws2 In wb2.Worksheets
          If WorksheetFunction.CountIf(macrosheet.Range("A:A"), ws2.Name) > 0 Then
             With ws2
              For Each rngCell In .UsedRange
                  *If Trim(rngCell.Value) <> vbNullString Then* rngCell.Value = Trim(rngCell.Value)
              Next rngCell
            End With
          Else
            Application.DisplayAlerts = False
            ws2.Delete
            Application.DisplayAlerts = True
          End If
        Next ws2
       
        wb2.Save
        macroobk.Activate
        Application.Goto macrosheet.Cells(1)
        Application.ScreenUpdating = True
        Set rngCell = Nothing
        Set wb2 = Nothing
        Set wsAct = Nothing
        Set myWb = Nothing
         
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Runtime Error Type Mismatch

    Are there any errors in any of the cells in any of the worksheets?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    06-18-2012
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Runtime Error Type Mismatch

    Quote Originally Posted by Norie View Post
    Are there any errors in any of the cells in any of the worksheets?
    No errors in the cells of the worksheets. Also the code in asterisk is the part that I need to debu.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Runtime Error Type Mismatch

    I know which line is causing the problem.

    The only reason I can see that code causing the described problem is if a cell had an error in it.

    What is the line of code meant to be doing anyway?
    Last edited by Norie; 05-08-2013 at 08:45 PM.

  5. #5
    Registered User
    Join Date
    06-18-2012
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Runtime Error Type Mismatch

    I'm not sure as I had help with this code. I think it's checking to see if the value in the cell is blank, and if its not, then it takes out any spaces if the cell value starts with spaces? If it's difficult to pinpoint the issue, is there a way to modify this code to get it to work?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Runtime Error Type Mismatch

    I don't think the code is the problem, it's the data.

    This might work.
            For Each rngCell In .UsedRange
                  If Not IsError(rngCell.Value) Then
                  If Trim(rngCell.Value) <> vbNullString Then rngCell.Value = Trim(rngCell.Value)
                  End If
              Next rngCell
            End With
    By the way, I'm not sure you need the If Trim(rngCell.Value) <> vbNullString part.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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