Can anyone think of a better way to write this VBA or to turn it into a UDF?

VBE313

Well-known Member
Joined
Mar 22, 2019
Messages
686
Office Version
  1. 365
Platform
  1. Windows
Code:
Sub test4opsgroup()
Application.ScreenUpdating = False
ActiveSheet.unprotect
Dim cl As Object
Dim l As Long, strCells As String
Dim strpart As String
Dim min As Range
Dim numrows As Long
Dim numcolumns As Long
Dim partnum As Range
Dim Qty As Range


 ActiveSheet.Range("T2").Select
      For Each cl In ActiveSheet.Range("OpsGroup")
 l = ActiveCell.Row
        strCells = "T" & l
        Range(strCells).Select
        
        If ActiveCell.Value = "" Then
Application.ScreenUpdating = True
Exit Sub
Else
End If
R
    If ActiveCell.Value = "TOP LEVEL" Then
    ActiveCell.Offset(0, -1).Select
    Set partnum = ActiveCell
Range("AB" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell = partnum
Range("AC" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell = partnum


Range(strCells).Select
Else


If ActiveCell.Value <> "TOP LEVEL" Then
Range("AB" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell = partnum
Range(strCells).Select
Else


End If
End If
ActiveCell.Offset(1, 0).Select
Next cl
Application.ScreenUpdating = True
ActiveSheet.Protect
End Sub
 
Last edited by a moderator:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
What is the range of OpsGroup?
 
Upvote 0
Hi Fluff,

the range for ops group is any column so let’s use C for example. “C3:C998”
 
Upvote 0
How about
Code:
Sub test4opsgroup()
   Application.ScreenUpdating = False
   ActiveSheet.Unprotect
   Dim Cl As Range
   
   For Each Cl In ActiveSheet.Range("OpsGroup")
      With Range("T" & Cl.Row)
         Select Case .Value
            Case ""
               Exit Sub
            Case "TOP LEVEL"
               Range("AB" & Rows.Count).End(xlUp).Offset(1).Value .Offset(, -1).Value
               Range("AC" & Rows.Count).End(xlUp).Offset(1).Value .Offset(, -1).Value
            Case Else
               Range("AB" & Rows.Count).End(xlUp).Offset(1).Value .Offset(, -1).Value
         End Select
      End With
   Next Cl
   ActiveSheet.Protect
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,573
Messages
6,120,310
Members
448,955
Latest member
Dreamz high

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top