Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8581795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:08:16+00:00 2026-06-11T21:08:16+00:00

I am trying to get this sub to work but the operationalRange variable is

  • 0

I am trying to get this sub to work but the operationalRange variable is not being assigned. Despite the fact that the function selectBodyRow(bodyName) works fine.

Sub sortRows(bodyName As String, ByRef wksht As Worksheet)
  Dim operationalRange As Range

  Set operationalRange = selectBodyRow(bodyName)


  Debug.Print "Sorting Worksheet: " & wksht.Name

  If Not operationalRange Is Nothing Then
    operationalRange.Select
    Debug.Print "Sorting " & operationalRange.Count & "Rows."
    ActiveWorkbook.Worksheets(wksht.Name).Sort.SortFields.Clear
    ActiveWorkbook.Worksheets(wksht.Name).Sort.SortFields.Add Key:=operationalRange, _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets(wksht.Name).Sort.SortFields.Add Key:=operationalRange, _
          SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets(wksht.Name).Sort
          .SetRange operationalRange
          .Header = xlGuess
          .MatchCase = False
          .Orientation = xlTopToBottom
          .SortMethod = xlPinYin
          .Apply
    End With
  Else
   MsgBox "Body is not being Set"
  End If
End Sub

The Sub being called by the above Sub is:

Function selectBodyRow(bodyName As String) As Range
Dim rangeStart As String, rangeEnd As String
Dim selectionStart As Range, selectionEnd As Range
Dim result As Range, srchRng As Range, cngrs As Variant

If bodyName = "WEST" Then
    rangeStart = "<-WEST START->"
    rangeEnd = "<-WEST END->"
ElseIf bodyName = "EAST" Then
    rangeStart = "<-EAST START->"
    rangeEnd = "<-EAST END->"
End If

Set srchRng = Range("A:A")
srchRng.Select

Set selectionStart = srchRng.Find(What:=rangeStart, After:=ActiveCell, LookIn _
        :=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
       xlNext, MatchCase:=False, SearchFormat:=False)

Set selectionEnd = srchRng.Find(What:=rangeEnd, After:=ActiveCell, LookIn _
        :=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
       xlNext, MatchCase:=False, SearchFormat:=False)

Set result = Range(selectionStart.Offset(1, 0), selectionEnd.Offset(-1, 0))
result.EntireRow.Select
End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:08:17+00:00Added an answer on June 11, 2026 at 9:08 pm

    Try, as Passerby suggested, to set your function to a range

        set selectBodyRow=result
    

    as in:

    Function selectBodyRow(bodyName As String) As Range
    Dim rangeStart As String, rangeEnd As String
    Dim selectionStart As Range, selectionEnd As Range
    Dim result As Range, srchRng As Range, cngrs As Variant
    
    If bodyName = "WEST" Then
        rangeStart = "<-WEST START->"
        rangeEnd = "<-WEST END->"
    ElseIf bodyName = "EAST" Then
        rangeStart = "<-EAST START->"
        rangeEnd = "<-EAST END->"
    End If
    
    Set srchRng = Range("A:A")
    srchRng.Select
    
    Set selectionStart = srchRng.Find(What:=rangeStart, After:=ActiveCell, LookIn _
            :=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
           xlNext, MatchCase:=False, SearchFormat:=False)
    
    Set selectionEnd = srchRng.Find(What:=rangeEnd, After:=ActiveCell, LookIn _
            :=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
           xlNext, MatchCase:=False, SearchFormat:=False)
    
    Set result = Range(selectionStart.Offset(1, 0), selectionEnd.Offset(-1, 0))
    result.EntireRow.Select
    
    set selectBodyRow=result
    'or set selectBodyRow=result.entirerow
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get this working but for some reason it's just not right.
I am having trouble trying to get iterators for inner sub-containers. Basically imagine this
Trying to get this expression to work, can someone look at it and tell
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {
I've been racking my brain trying to get this to work. My event for
I'm new to VBA but I'm trying to get a DYMO LabelWriter to work
I'm trying to get my .htaccess file to work from the root, but also
I've read loads of answers on SO, but still can't get this to work.
Basically I'm trying to get a distinct count within this cubed result. But unfortuantly
Been trying to get this up and running for a while now. Basically i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.