Computer/VBA

From Kimmel Lab Wiki

Jump to: navigation, search

This page is for explaining VBA and storing small VBA scripts.

Sub Rearrange()
   'This line creates an input box so we can get the number of landmarks from the user.
   inputNum = Val(InputBox(Prompt:="Number of Landmarks?", Title:="Number of Landmarks?"))
   n = 1
   'The do loop loops through all the data in the file.
   Do
       'The for loop loops through all the land marks
       For i = 1 To inputNum
           currentRow = ((n - 1) * inputNum) + i
           'This section cuts and pastes the x coordinate.
           Cells(currentRow, 1).Select
           Selection.Cut
           Cells(n, (i * 2) - 1).Select
           ActiveSheet.Paste
           
           'This section cuts and pastes the y coordinate.
           Cells(currentRow, 2).Select
           Selection.Cut
           Cells(n, (i * 2)).Select
           ActiveSheet.Paste
       Next i
       n = n + 1
   'When we find an empty cell we stop looping.
   Loop Until IsEmpty(Cells(((n - 1) * inputNum) + 1, 1))
End Sub

Personal tools