0
Sub MS()    

Data = Sheets("Tabelle1").Select   
Rows("1:1").Select
Rows("11409:11409").Select

Dim bilder As Long
Dim n As Long
Dim d As Long
Dim t As Long

bilder = 64
n = 1    
d = 0
t = 0

'Dim i As Long   

'For i = 1 To lastrow

Range("a1:a" & Cells(Rows.Count, 1).End(xlUp).Row).Select

Range("b1:b" & Cells(Rows.Count, 1).End(xlUp).Row).Select

'Range("a1").Select

'Range("b1").Select

Range("a1,b1").Select

Do While ActiveCell.Value <> ""       
    Radius = Sqr(Range("A1").Value * Range("A1").Value + Range("B1").Value * Range("B1").Value)      
    ActiveCell.Offset(1, 1).Select 
Loop    

End Sub

2 Answers2

1

I'm not sure why you'd want to do it this way (given that it can be done with a simple formula in-cell), but looking at the remnants of code in your question we can see what you're trying to achieve. Here's how I'd do it:

Sub MS()

    Dim sht As Worksheet, StartRow As Long, LastRow As Long, OutputColumn As Long
    Dim SideA As Double, SideB As Double, SideC As Double
    
    With Worksheets("Tabelle1")
    
        'Set StartRow to the first row of your data ignoring headers
        StartRow = 2
        
        'Locate LastRow as last occupied cell in column A
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        
        'Set OutputColumn to 3
        OutputColumn = 3
        
        'Start loop
        For r = StartRow To LastRow
            SideA = .Cells(r, 1).Value
            SideB = .Cells(r, 2).Value
            SideC = Sqr(SideA * SideA + SideB * SideB)
            .Cells(r, OutputColumn).Value = SideC
        Next
        
    End With

End Sub

Output:

enter image description here

CLR
  • 11,284
  • 1
  • 11
  • 29
1

You do not need to select the range to work with it. You may want to see How to avoid using Select in Excel VBA

In your code you are not writing the output to any cell. Here are two ways that will help you achieve what you want.

NON VBA - WAY 1

Put the formula =SQRT(A1*A1+B1*B1) or =SQRT(A1^2+B1^2) in C1 and drag it down

VBA - WAY 2 (Without Looping)

Option Explicit

Sub Sample()
    Dim ws As Worksheet
    Dim lRow As Long
    
    Set ws = Sheets("Tabelle1")
    
    With ws
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row
        
        With .Range("C1:C" & lRow)
            .Formula = "=SQRT(A1*A1+B1*B1)"
            .Value = .Value
        End With
    End With
End Sub

VBA - WAY 3 (Without Looping) Slightly complicated way of doing this. Explanation can be seen HERE

Option Explicit

Sub Sample()
    Dim ws As Worksheet
    Dim lRow As Long
    
    Set ws = Sheets("Tabelle1")
    
    With ws
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row
        
        With .Range("C1:C" & lRow)
            .Value = Evaluate("index(SQRT((A1:A" & lRow & _
                              ")^2+(B1:B" & lRow & _
                              ")^2),)")

        End With
    End With
End Sub
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250