run time error 1004 cant do this to merge cells

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hello, i am getting a run time error we cant do this to merged cells. e29 is merged so using columns E and F and the then what the code is doing is pasting the formula into that cells. Then trying to copy the formula paste it into the cells basically repasting it into e29 when "I" is one then when "I" = 2 it will paste into i29, however I29 is also merge not sure how to get rid of this error

VBA Code:
Sub Formula_change()

Dim rowNum, ColAmt, colNum, colOff, i As Integer

rowNum = 29
ColAmt = 4
colNum = 4
colOff = 1
i = 1

Dim main As Workbook
Set main = Application.ThisWorkbook
Dim main_ws As Worksheet

Dim page1 As Worksheet
Set page1 = main.Worksheets("Page 1")

page1.Range("E29").FormulaR1C1 = "=IF(IFERROR(VLOOKUP(R[-37]C[-1],'List'!R4C7:R200C18,12,FALSE),0)=""Please fill out"",""--"",IFERROR(VLOOKUP(R[-37]C[-1],'List'!R4C7:R200C18,12,FALSE),0))"

Application.CutCopyMode = False
page1.Range("E29").Copy
page1.Cells(29, (((i - 1) * (entColAmtCol)) + colNum) + colOffFourCol).PasteSpecial Paste:=xlPasteFormulasAndNumberFormats

End Sub

The error is happening here in the copde

page1.Cells(29, (((i - 1) * (entColAmtCol)) + colNum) + colOffFourCol).PasteSpecial Paste:=xlPasteFormulasAndNumberFormats
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
The easiest way to avoid the problem is to avoid merging cells. This is considered best practice by experienced Excel users.

Merging cells is appropriate in a sheet which is used only to display outputs, but is never appropriate in a sheet used for data or for calculations.
 
Upvote 0
The easiest way to avoid the problem is to avoid merging cells. This is considered best practice by experienced Excel users.

Merging cells is appropriate in a sheet which is used only to display outputs, but is never appropriate in a sheet used for data or for calculations.
Gotcha, i guess a good work around is change it to this
VBA Code:
Sub Formula_change()

Dim rowNum, ColAmt, colNum, colOff, i As Integer

rowNum = 29
ColAmt = 4
colNum = 4
colOff = 1
i = 1

Dim main As Workbook
Set main = Application.ThisWorkbook
Dim main_ws As Worksheet

Dim page1 As Worksheet
Set page1 = main.Worksheets("Page 1")

page1.Cells(29, (((i - 1) * (entColAmtCol)) + colNum) + colOffFourCol).FormulaR1C1 = "=IF(IFERROR(VLOOKUP(R[-37]C[-1],'List'!R4C7:R200C18,12,FALSE),0)=""Please fill out"",""--"",IFERROR(VLOOKUP(R[-37]C[-1],'List'!R4C7:R200C18,12,FALSE),0))"

believe that may work, its not pasting into merge cells but instead just putting the formula
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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