populate cells on current sheet depending on data on another sheet

would appreciate an expert providing me with VBA code that will populate cells on Sheet2 based on the number of rows in Sheet1.

i.e. Sheet 1 contains data in cells A2-P2. [Row 1 is the header] The number of rows will change daiy so today there could be 50 rows tomorrow 250 next day 100 and so on.

depending on the number of rows each day I will clear the data from my sheet 2 and then I want to add a formula based on the same number of rows.

So if there are 50 rows today I need to populate cell B2 in sheet 2 with =Sheet1!A2&Sheet1!D2&Sheet1!E2&Sheet1!F2&Sheet1!C2 and copy this down to cover the same number of rows that are in sheet 1.

I also have formulas in C2,D2 and E2 but I presume I can replicate the code that an expert provides for these.

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


pls try

Sub macro()

Set OrigSheet = ActiveWorkbook.Sheets("Sheet1")
Set DestSheet = ActiveWorkbook.Sheets("Sheet2")
NrOfRows = OrigSheet.Range("A" & Rows.Count).End(xlUp).Row - 1
Range(Range("A2"), Range("A" & Rows.Count).End(xlUp)).EntireRow.Delete
DestSheet.Range("A2").Formula = "=Sheet1!A2&Sheet1!D2&Sheet1!E2&Sheet1!F2&Sheet1!C2"
DestSheet.Range("A2").Copy Destination:=DestSheet.Range("A2").Resize(NrOfRows)

End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JagwarmanAuthor Commented:
perfect as usual Rgonzo many thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.