Excel VBA Run-time error '13' Type mismatch

rynxzard

New Member
Joined
Jan 13, 2014
Messages
2
I created a macro for a file but i am stuck on the line that was colored red
who can help me with this error.



Dim listSheetRange As Range
'Sheet to copy data From
Dim listSheet As Worksheet
'Sheet to copy data To
Dim actionSheet As Worksheet
Set listSheetRange = Worksheets("TRACKER").UsedRange
Set listSheet = Worksheets("TRACKER")
Set actionSheet = Worksheets("Daily HOLD")
'Clear the To Sheet
actionSheet.UsedRange.Clear
'Row 1 of From Sheet contains the data to match
'Copy Header Row i.e Row 2 of From Sheet
listSheet.Rows(1).Copy Destination:=actionSheet.Rows(1)
If UCase(listSheet.Columns(6)) = "HOLD" Then
listSheet.Columns(2).Copy Destination:=actionSheet.Columns(2)
listSheet.Columns(3).Copy Destination:=actionSheet.Columns(3)
listSheet.Columns(4).Copy Destination:=actionSheet.Columns(4)
listSheet.Columns(5).Copy Destination:=actionSheet.Columns(5)
listSheet.Columns(6).Copy Destination:=actionSheet.Columns(6)
listSheet.Columns(7).Copy Destination:=actionSheet.Columns(7)
listSheet.Columns(8).Copy Destination:=actionSheet.Columns(8)
listSheet.Columns(9).Copy Destination:=actionSheet.Columns(9)
listSheet.Columns(10).Copy Destination:=actionSheet.Columns(10)
End If

'hide any unwanted columns
actionSheet.Columns(1).Hidden = 1
actionSheet.Activate
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
It don't like trying to pick one value out of an entire column. Maybe a statement like this would work better.
Code:
If Application.CountIf(UCase(listSheet.Columns(6)), "HOLD") > 0 Then
This will allow VBA to look at the column to see if that value is there somewhere. If it is then then the other statements will execute, if not it will by pass the other statements.
 

rynxzard

New Member
Joined
Jan 13, 2014
Messages
2
hello JLGWhiz still did not work..same error appears can, do you have another way to solve it?

thank you!
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
hello JLGWhiz still did not work..same error appears can, do you have another way to solve it?

thank you!

Remove the UCase function.
Code:
If Application.CountIf(listSheet.Columns(6), "HOLD") > 0 Then
 

Watch MrExcel Video

Forum statistics

Threads
1,123,158
Messages
5,600,052
Members
414,357
Latest member
Gemma_R

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
Top