I'm trying to figure out how to use VB to sort a variable number of range "blocks" on a worksheet. For some reason, I can't get an image file to upload here so I'll try to explain.
My worksheet has a "header block" which is range ("D1:BM9") and below the header block is a variable number of "agenda blocks", (which are identical in structure) the first of which is range ("D10:BM19"), the second would be range ("D20:BM29") and so forth, depending on how many agenda blocks the user has added. Cells D10 & D20, etc. display the row number (10, 20, etc.) which then becomes the identifying number for that agenda block.
Using a macro button, I would like to be able to sort the variable number of agenda blocks based on either the its priority which is defined as text (Critical, High, Medium, or Low) in range ("D15") for the first agenda block and range ("D25") in the second agenda block, etc., or by the person accountable which is defined as text (First & Last Name) in range ("Z12") for the first agenda block, and range ("Z22") in the second agenda block, etc.
The code below shows that I'm assuming I need to first determine the number of agenda blocks on the worksheet and then find a way to name the ranges so I can sort them but I'm not convinced this is right. And clearly, you can see where I'm stuck!
Sub SortAgendaBlocks()
' This macro sorts the agenda blocks by either priority or person accountable
' Find the number of agenda blocks on the worksheet
Dim RngNum As Integer
Dim RowStart As Long
Dim RowEnd As Long
RngNum = Application.Sum(Range("d10:d1000"))
RngNum = RngNum - 10
RngNum = RngNum / 10
' Name the ranges
RowStart = 10
RowEnd = RowStart + 9
For i = 1 To RngNum
Cells("d" & RowStart, "d" & RowEnd).Name = AB
Next i
End Sub
If anyone would provide some code or guidance, I would appreciate it very much. Thanks very much for considering this! John
My worksheet has a "header block" which is range ("D1:BM9") and below the header block is a variable number of "agenda blocks", (which are identical in structure) the first of which is range ("D10:BM19"), the second would be range ("D20:BM29") and so forth, depending on how many agenda blocks the user has added. Cells D10 & D20, etc. display the row number (10, 20, etc.) which then becomes the identifying number for that agenda block.
Using a macro button, I would like to be able to sort the variable number of agenda blocks based on either the its priority which is defined as text (Critical, High, Medium, or Low) in range ("D15") for the first agenda block and range ("D25") in the second agenda block, etc., or by the person accountable which is defined as text (First & Last Name) in range ("Z12") for the first agenda block, and range ("Z22") in the second agenda block, etc.
The code below shows that I'm assuming I need to first determine the number of agenda blocks on the worksheet and then find a way to name the ranges so I can sort them but I'm not convinced this is right. And clearly, you can see where I'm stuck!
Sub SortAgendaBlocks()
' This macro sorts the agenda blocks by either priority or person accountable
' Find the number of agenda blocks on the worksheet
Dim RngNum As Integer
Dim RowStart As Long
Dim RowEnd As Long
RngNum = Application.Sum(Range("d10:d1000"))
RngNum = RngNum - 10
RngNum = RngNum / 10
' Name the ranges
RowStart = 10
RowEnd = RowStart + 9
For i = 1 To RngNum
Cells("d" & RowStart, "d" & RowEnd).Name = AB
Next i
End Sub
If anyone would provide some code or guidance, I would appreciate it very much. Thanks very much for considering this! John