none
run macro on multiple cells RRS feed

  • Question

  • I have a macro that looks up the OU a server is in.  It currently looks at the server name in A2 and returns the OU in B2.  Now I want to make it so that it does this for any server entered in column A.  How do I retrieve the number of rows entered?

    Currently:

    strServerName = Range("A2").Value

    do stuff

    Range("B2").Value = strEndResult


    Friday, July 27, 2018 9:07 PM

Answers

  • Like this:

    Sub ListOUs()
        Dim r As Long
        Dim m As Long
        Dim strServerName As String
        Dim strEndResult As String
        Application.ScreenUpdating = False
        m = Range("A" & Rows.Count).End(xlUp).Row
        For r = 2 To m
            strServerName = Range("A" & r).Value
            ' ...
            Range("B" & r).Value = strEndResult
        Next r
        Application.ScreenUpdating = True
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Proposed as answer by Terry Xu - MSFT Monday, July 30, 2018 3:13 AM
    • Marked as answer by Carl_S_S Monday, July 30, 2018 3:08 PM
    Friday, July 27, 2018 9:25 PM

All replies

  • Like this:

    Sub ListOUs()
        Dim r As Long
        Dim m As Long
        Dim strServerName As String
        Dim strEndResult As String
        Application.ScreenUpdating = False
        m = Range("A" & Rows.Count).End(xlUp).Row
        For r = 2 To m
            strServerName = Range("A" & r).Value
            ' ...
            Range("B" & r).Value = strEndResult
        Next r
        Application.ScreenUpdating = True
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Proposed as answer by Terry Xu - MSFT Monday, July 30, 2018 3:13 AM
    • Marked as answer by Carl_S_S Monday, July 30, 2018 3:08 PM
    Friday, July 27, 2018 9:25 PM
  • That worked perfectly Hans.  Thank you.
    Monday, July 30, 2018 3:08 PM