Code works when 2 cells are populated, but doesn't work when they are empty. I get Run-Time Error 1004

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
1,027
Office Version
  1. 365
Platform
  1. Windows
Hello All,

The code below is for 12 cells only (all other cells in row 6 are locked), one for each month in row 6.

The "GETPIVOTDATA" code will populate the each month below.
Jan data will go in the C6 cell
Feb data will go in the D6 cell
Mar data will go in the E6 cell, etc....

The issue is that when there is no data in January (C6) or February (D6), the code below gives me an error.

The error I get is "Run-Time Error 1004".

It is also worthy to note that in row 6, all cells are locked from editing except cells C6 through N6.

Again, the code works perfectly if there is already data in BOTH the C6 AND D6 cells. I would like this to work even if one or both of them are blank.

Can anyone make this happen?

Thanks much!


Code:
 Range("C6").Select
ActiveCell.End(xlToRight).Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = _
        "=GETPIVOTDATA(""REPORT"",'Customer Chart'!R1C1,""NAME"",""John"")"
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,215,269
Messages
6,123,976
Members
449,138
Latest member
abdahsankhan

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