help writing a macro.

  • Thread starter Thread starter keyur
  • Start date Start date
K

keyur

Hi

Here's my situation

i have 3 columns A,B,C in file X. C has a formulae where
as A and B are typed values. Every day i have new values
for A and B and i get them from another file Y. I copy the
columns A&B from Y and paste in X. If the new list is
smaller than the previous one, perfect, the macro deletes
the rows with any empty cell in the row. if the new list
is bigger than in the macro i want to go to C2 and fill
down. the only thing i dont know is how to write a
statement that will fill down only till the last occupied
cell in A.

filling down first and then deleting rows with emppty
cells might not work as the size of the list is very
unpredictable. and i dont want it to fill down like 1000
rows when might just have 100 occupied cells in A.

thanks for any help.
 
One way:

Sub AddFormulaToC()
Columns("C").ClearContents
Range("C1").Formula = "=sum(A1:B1)"
Range("C1:C" & _
Application.WorksheetFunction.Max _
(Range("A" & Rows.Count).End(xlUp).Row, _
Range("B" & Rows.Count).End(xlUp).Row)).FillDown
End Sub

Regards

Trevor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top