Click here to Skip to main content
14,662,846 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello everyone,
I'm trying to run VBA to put formula into a cell

Cells(10, 4).Formula = "=Max(H &""FirstRow""&,H &""LastRow""&)"

I get Run-time error '1004':


Thank you for your help

What I have tried:

I tried this

Cells(10, 4).Formula = "=Max(H2,H14)"

it works fine.
Posted
Updated 23-Feb-18 4:53am

Rate this:
Please Sign up or sign in to vote.

Solution 2

Quote:
Cells(10, 4).Formula = "=Max(H &""FirstRow""&,H &""LastRow""&)"

I get Run-time error '1004':

Because quotes are misplaced.
Try
Cells(10, 4).Formula = "=Max(H" & FirstRow & ",H" & LastRow & ")"
   
Comments
Member 13693055 23-Feb-18 12:08pm
   
Thank you very much
Rate this:
Please Sign up or sign in to vote.

Solution 1

Maybe that will bring you some clues about it:
VBA Tutorial: Find the Last Row, Column, or Cell on a Sheet[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100