Ideal Being
New Member
- Joined
- Mar 28, 2015
- Messages
- 16
Hi,
I have a table which can look like this (data are simplified) after some macros are activated:
<tbody>
</tbody>
I have a userform with listbox where are values A-Z and following logic:
The problem is when the macro is activated second time (let's say I want to add value B to column 2), the sort mechanism obviously does not work as it sorts blank cells:
Is there a way to tell the sort mechanism that it needs to expand selection and take all 3 rows related to value in column 2? So the final table after adding B into column 2 would look like this:
<tbody>
</tbody>All suggestions are appreciated. Thanks to everyone for your time and patience!
I have a table which can look like this (data are simplified) after some macros are activated:
Column 1 | Column 2 | Column 3 | Column 4 |
1 | A | ||
cat | |||
3 | C | dog | |
D | |||
bird |
<tbody>
</tbody>
I have a userform with listbox where are values A-Z and following logic:
- Select multiple items from listbox
- Click add button to add them into active sheet
- Delete duplicity (if you add let's say A and then you want to add it again, it does NOT add it - this can guarantee unique values)
- Sort whole table by column 2 in alphabetical order
- Add 2 rows for each row which has value in column 2
The problem is when the macro is activated second time (let's say I want to add value B to column 2), the sort mechanism obviously does not work as it sorts blank cells:
Code:
'Sorts test in ascending order by Column C in Range B5:J1000
Columns("C:C").Select
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range _
("C1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveSheet.Sort
.SetRange Range("B5:J1000")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Is there a way to tell the sort mechanism that it needs to expand selection and take all 3 rows related to value in column 2? So the final table after adding B into column 2 would look like this:
Column 1 | Column 2 | Column 3 | Column 4 |
1 | A | ||
cat | |||
2 | B | ||
3 | C | dog | |
D | |||
bird |
<tbody>
</tbody>