UNMERGE RANGE VBA ERROR

RedOctoberKnight

Board Regular
Joined
Nov 16, 2015
Messages
150
Office Version
  1. 2016
Platform
  1. Windows
Good Morning,

I have a worksheet that copies and pastes from another workbook. It works perfectly except for when I need to "pull" the information again. I get a merged cell error. So i'm trying to figure out how to unmerge range (A1:S100) and then have it copy the info.

I get an error with my following code. I'm not sure where to put the unmerge action.

VBA Code:
Public Sub Copy_Range_From_Truck_Schedules()

       Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim tsWorkbook As Workbook

Set tsWorkbook = Workbooks.Open(ThisWorkbook.Path & "\truckschedulesdualsides.xlsx")
With ThisWorkbook.ActiveSheet
tsWorkbook.Worksheets(.Name).Range("A1:S100").Copy
.Range("A1:S100").UnMerge
.Range("A1").PasteSpecial xlPasteValues
.Range("A1").PasteSpecial xlPasteFormats
.Range("H:J").EntireColumn.AutoFit
.Range("M:O").EntireColumn.AutoFit
      .Range("R:R").EntireColumn.ColumnWidth = 25

   End With
tsWorkbook.Close False
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True


End Sub

Any help would be much appreciated and as always, thank you.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Which sheet are the merged cells on, the copy sheet or the paste sheet?
 
Upvote 0
Well the copy sheet has merged cells and my original code (just take out the .Range("A1:S100").UnMerge) worked fine. My problem is when I run the code again, I get a merged cell error which I assume is on my paste sheet. So I want to unmerge the cells on the paste sheet and then paste the info.
 
Upvote 0
What error number & message do you get & what line is highlighted when you click debug?
 
Upvote 0
1004
pastespecial method of range class failed.

.Range("A1").PasteSpecial xlPasteValues is giving me the error now.
 
Upvote 0
Try moving the unmerge line before the copy line.
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,384
Members
449,080
Latest member
Armadillos

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