run time error 1004 cant do this to merge cells

drop05

Board Regular
Joined
Mar 23, 2021
Messages
204
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Jon Peltier

MrExcel MVP
Joined
May 14, 2003
Messages
5,258
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
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.
 

drop05

Board Regular
Joined
Mar 23, 2021
Messages
204
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,175,517
Messages
5,897,895
Members
434,685
Latest member
asdf12l3

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