mismatch error

Status
Not open for further replies.

londa_vba

Board Regular
Joined
May 11, 2023
Messages
61
Office Version
  1. 365
Platform
  1. Windows
Code worked until I messed with it. :( Tweak needed.
I wanted to move the pasting destination to begin at AA3 on Sheet C but I am now getting an error message regarding line 29 type mismatch



VBA Code:
Sub PopulateCEPrep()
Dim arrRanges() As String
Dim arrWorksheets() As String
Dim Ws As Worksheet
Dim i As Integer
Dim ii As Integer
Dim intRow As String
Dim rng As Range
ActiveWorkbook.Save
    
Worksheets("Sheet C").Activate
    
With Worksheets("Sheet C")
.Range("AA3:AA" & .Cells(.Rows.Count, "AA").End(xlUp).Row).Value = ""
End With
arrRanges = Split("B8:B33,B39:B64,B70:B95,B101:B126", ",")
        
arrWorksheets = Split("G,R,Y", ",")
    
intRow = 3
    
For i = LBound(arrWorksheets) To UBound(arrWorksheets)
        
For ii = LBound(arrRanges) To UBound(arrRanges)
            
For Each rng In Worksheets(arrWorksheets(i)).Range(arrRanges(ii))
If Len(Trim(rng.Value)) > 0 Then
Worksheets("Sheet C").Cells(intRow, 27).Value = rng.Value
intRow = intRow + 1
End If
 Next rng
            
 Next ii
        
 Next i
    
Worksheets("Sheet C").Range("AA3").Select
    
'MsgBox intRow - 5 & " rows of data copied", vbOKOnly, "Confirmation"
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
What is the exact error message you are getting? And on which line of code?

If you have an error value anywhere in the ranges "B8:B33,B39:B64,B70:B95,B101:B126" in worksheets "G", "R" or "Y", you will get a Run-time error '13': Type mismatch error when you test the cell value on this line of code:

If Len(Trim(rng.Value)) > 0 Then
 
Upvote 0
Duplicate to: VBA copy and paste

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top