1

I need to call an homemade function (GetCoordinates) in a loop and apply it at each loop step.

I have a column with data (Starting at L2) and I need to apply my personnal function GetCoordinates to this data and write the result on the column next to it (so starting at M2)

NumRows = Range("L2", Range("L2").End(xlDown)).Rows.Count
      Range("L2").Select
      For x = 1 To NumRows
         Selection.Offset(, 1).Formula = "=GetCoordinates(L&x)"
         ActiveCell.Offset(1, 0).Select
      Next

My problem is that I don't know how to apply my function to each cell. How should it be written so that the function is called for each cell in the loop? (The GetCoordinates function works fine)

2 Answers 2

1

Try putting in all the formulas without a loop. To write te formulas in column M and use column L as the formulas argument then use,

 Range(cells(2, "M"), cells(rows.count, "L").End(xlup).offset(0, 1)).Formula = _
     "=GetCoordinates(L2)"

Your own might have been closer with,

Selection.Offset(, 1).Formula = "=GetCoordinates(L" & x & ")"

But you were mismatching Do ... While and For ... Next loops.

Sign up to request clarification or add additional context in comments.

2 Comments

What column is the input data and what column do you want the formula in?
The input is the L column and the result should be in the M column (both on the same line)
1

Try this

 NumRows = Range("L" & Rows.Count).End(xlUp).Row

  For x = 2 To NumRows
     Cells(x, "M").Value = GetCoordinates(Cells(x, "L"))
  Next

2 Comments

Thank you it worked as well. Yet I don't know which one of the 2 solutions is the fastest (i have about 6000 lines to process)
Add a timer at start of code Debug.Print "Start Time: " & Time and at the end Debug.Print "Start Time: " & Time , you will come to know. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.