Type mismatch... VBA

p4nny

Board Regular
Joined
Jan 13, 2015
Messages
246
Hi

When I run the following code I get the 'Type Mismatch' error:

The code works ok for the first export (in terms of saving in location), however will not work thereafter.


Sub exportsheets()

Dim wbNew As Workbook
Dim rngTM As Range
Dim strPath As String


Application.ScreenUpdating = False


strPath = "C:\Users\pandoan\Desktop\test\"
Set rngTM = Sheets("Flow TM's").Range("A1")


Do
Sheets(Array("HC pivot TM data", rngTM.Value)).Copy
Set wbNew = ActiveWorkbook
With wbNew
.Sheets("HC pivot TM data").Visible = False
Application.Goto .Sheets(1).Range("B13"), True

wbNew.SaveAs strPath & rngTM.Value & Format(Date, "ddmmmyyyy") & ".xlsx"


End With
Set rngTM = rngTM.Offset(1, 0)
Loop Until rngTM.Value


Application.ScreenUpdating = True

End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
When you click on Debug, which line of code is highlighted? Does it help if you replace...

Code:
Loop Until rngTM.Value

with

Code:
Loop Until Len(rngTM.Value) = 0

???
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

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