Problem with Run Time 1004 Error

jconkl02

Board Regular
Joined
May 25, 2016
Messages
55
To start, I know just enough VBA to be dangerous. I know my code is sloppy and ineffecient. I'm working on that. I understand that .Select is kind of frowned upon, especially with ranges but I have not figured out the way around it yet.


With that said here is my problem. I have a formula that Board Regulars AlanY and etaf were nice enough to help me with. Now I'm trying to paste that formula in every row when there is something in column A of that row.


Code:
Columns("F:F").Select    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "Shift"
    Range("F2:F" & Cells(Rows.Count, "A").End(xlUp).Row).FormulaR1C1 = _
        "=IF(AND(RC[-1]>=INDEX('Chart Data-Email Shift'!C3,MATCH(""Day Shift Start"",'Chart Data-Email Shift'!C2,0)),RC[-1]<=INDEX('Chart Data-Email Shift'!C3,MATCH(""Day Shift Start"",'Chart Data-Email Shift'!C2,0))+8/24),""Days"",IF(AND(RC[-1]>=INDEX('Chart Data-Email Shift'!C3,MATCH(""Swing Shift Start"",'Chart Data-Email Shift'!C2,0)),RC[-1]<=INDEX('Chart Data-Email Shif" & _
        "TCH(""Swing Shift Start"",'Chart Data-Email Shift'!C2,0))+8/24),""Swings"",""Mids""))"


Excel 2012
ABCDEF
1SEQNotification StatusDateDateTimeShift
27489523-Update-42968.78263888897489523Update08/21/20176:47:00 PM
37489523-Final-42969.14861111117489523Final08/22/20173:34:00 AM
47445261-Initial-42969.38055555567445261Initial08/22/20179:08:00 AM
57445261-Final-42969.41041666677445261Final08/22/20179:51:00 AM
67084220-Update-42969.65277777787084220Update08/22/20173:40:00 PM
77341942-Final-42969.67916666677341942Final08/22/20174:18:00 PM
87084220-Update-42969.69444444447084220Update08/22/20174:40:00 PM
97084220-Final-42969.71597222227084220Final08/22/20175:11:00 PM

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
IMPORT-EMAIL




But I get the Run time 1004 error. I have tried it in blank workbooks as well with the same result. Here is the worksheet:
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
'Chart Data-Email Shif" & _
"TCH(""Swing Shift Start"",'Chart Data-Email Shift'!C2,0))+8/24),""Swings"",""Mids""))"

Looks like two incomplete words. That would throw the error.
 
Upvote 0
Solution
Looks like two incomplete words. That would throw the error.

That is weird. The misspelled words were not in the original formula. It wasn't until I was recording the macro and pasted the formula into the cell that they showed up misspelled.

However, that did not fix my problem. I'm still getting the Run Time 1004 at the same spot. Here is the original formula.
Code:
=IF(AND(F2>=INDEX('Chart Data-Email Shift'!$C:$C,MATCH("Day Shift Start",'Chart Data-Email Shift'!$B:$B,0)),F2<=INDEX('Chart Data-Email Shift'!$C:$C,MATCH("Day Shift Start",'Chart Data-Email Shift'!$B:$B,0))+8/24),"Days",IF(AND(F2>=INDEX('Chart Data-Email Shift'!$C:$C,MATCH("Swing Shift Start",'Chart Data-Email Shift'!$B:$B,0)),F2<=INDEX('Chart Data-Email Shift'!$C:$C,MATCH("Swing Shift Start",'Chart Data-Email Shift'!$B:$B,0))+8/24),"Swings","Mids"))

It's looking for the start/stop times of the different shifts that are on the "Chart Data-Email Shift" worksheet:
Excel 2012
BC
1ShiftTime
2Day Shift Start7:00 AM
3Day Shift End2:59 PM
4Swing Shift Start3:00 PM
5Swing Shift End10:59 PM
6Mid Shift Start11:00 PM
711:59 PM
812:00 AM
9Mid Shift End6:59 AM

<colgroup><col style="width: 25pxpx" https:="" www.mrexcel.com="" forum="" usertag.php?do="list&action=hash&hash=DAE7F5"" target="_blank"></colgroup><colgroup><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Chart Data-Email Shift



I want it to populate the cell in column F if there is anything in Column A.
 
Last edited:
Upvote 0
The 1004 run time error is normally attributable to incorrect or incomplete user input such as missing double, double quote marks in formulas to be pasted into cells, misspelled sheet names or difference in upper and lower case for case sensitive strings. The sheet names must be exact matches to the name on the sheet name tab and the sheets must exist. Also, if .Formula is used to assign the value to the cell the the A1 format must be used for the range references. If .FormulaR1C1 is used then the range references must be in R1C1 format.
 
Upvote 0
There is a bug in the macro recorder that will miss about 8 digits of long formulas if you record those formulas being committed to a cell.
 
Upvote 0
You need to add this to your formula string:

t'!C2,MA

so it becomes:

"=IF(AND(RC[-1]>=INDEX('Chart Data-Email Shift'!C3,MATCH(""Day Shift Start"",'Chart Data-Email Shift'!C2,0)),RC[-1]<=INDEX('Chart Data-Email Shift'!C3,MATCH(""Day Shift Start"",'Chart Data-Email Shift'!C2,0))+8/24),""Days"",IF(AND(RC[-1]>=INDEX('Chart Data-Email Shift'!C3,MATCH(""Swing Shift Start"",'Chart Data-Email Shift'!C2,0)),RC[-1]<=INDEX('Chart Data-Email Shift'!C2,MA" & _
"TCH(""Swing Shift Start"",'Chart Data-Email Shift'!C2,0))+8/24),""Swings"",""Mids""))"
 
Upvote 0
You need to add this to your formula string:

t'!C2,MA

so it becomes:

"=IF(AND(RC[-1]>=INDEX('Chart Data-Email Shift'!C3,MATCH(""Day Shift Start"",'Chart Data-Email Shift'!C2,0)),RC[-1]<=INDEX('Chart Data-Email Shift'!C3,MATCH(""Day Shift Start"",'Chart Data-Email Shift'!C2,0))+8/24),""Days"",IF(AND(RC[-1]>=INDEX('Chart Data-Email Shift'!C3,MATCH(""Swing Shift Start"",'Chart Data-Email Shift'!C2,0)),RC[-1]<=INDEX('Chart Data-Email Shift'!C2,MA" & _
"TCH(""Swing Shift Start"",'Chart Data-Email Shift'!C2,0))+8/24),""Swings"",""Mids""))"

steve the fish,

You were close. Actually what I needed to add was t'!C3,MA not t'!C2,MA. You got me on the right track and I truly appreciate your help.

Jason
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,664
Members
449,045
Latest member
Marcus05

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