Button to find and transfer data from one spread sheet to another biased on a specific variable

PA_VA13

New Member
Joined
Jul 2, 2020
Messages
28
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone!

So I was able to write a script that is attached to a button that would search for a specific variable in one sheet and then pull that data on the identified row to another sheet.

I receive a Run-time error "13": Type mismatch but the code still performs the task anyways.

Do I need to worry about this run-time error since it is still working? When I do the debug it shows that the issue involves my 'If Worksheets' line (in bold red in the below code).

This is the code:

Sub CaseAssignPathSH()

Dim lastrom As Long, erow As Long

'to check the last filled line on sheet neamed merge

lastrow = Worksheets("Merge").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow

If Worksheets("Merge").Cells(i, 20).Value = "SH" Then
Worksheets("Merge").Cells(i, 16).Copy
erow = Worksheets("PATH CASES").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Merge").Paste Destination:=Worksheets("PATH CASES").Cells(erow + 1, 1)
Worksheets("Merge").Cells(i, 17).Copy
Worksheets("Merge").Paste Destination:=Worksheets("PATH CASES").Cells(erow + 1, 2)
Worksheets("Merge").Cells(i, 18).Copy
Worksheets("Merge").Paste Destination:=Worksheets("PATH CASES").Cells(erow + 1, 3)

End If
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Maybe in column cell "T" you have some error like #VALUE #NA, etc

Try this:

VBA Code:
Sub CaseAssignPathSH()
  Dim c As Range
  For Each c In Sheets("Merge").Range("T2", Sheets("Merge").Range("T" & Rows.Count).End(3))
    If Not IsError(c) Then
      If c = "SH" Then c.Offset(, -4).Resize(1, 3).Copy Sheets("PATH CASES").Range("A" & Rows.Count).End(3)(2)
    End If
  Next
End Sub
 
Upvote 0
Maybe in column cell "T" you have some error like #VALUE #NA, etc

Try this:

VBA Code:
Sub CaseAssignPathSH()
  Dim c As Range
  For Each c In Sheets("Merge").Range("T2", Sheets("Merge").Range("T" & Rows.Count).End(3))
    If Not IsError(c) Then
      If c = "SH" Then c.Offset(, -4).Resize(1, 3).Copy Sheets("PATH CASES").Range("A" & Rows.Count).End(3)(2)
    End If
  Next
End Sub

It worked! Thank yo very much!
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,176
Members
448,948
Latest member
spamiki

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