ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba dynamic (https://www.excelbanter.com/excel-programming/444231-vba-dynamic.html)

danial mansoor

vba dynamic
 
hi experts!
i ve this macro but i want to make it dynamic how can i do it?

Sub Macro1()
€˜
€˜ Macro1 Macro
€˜
€˜finalrow = Cells(Rows.Count, 1).End(xlUp).Value
ActiveWorkbook.Worksheets(€œSheet2€³).Sort.SortF ields.Clear
ActiveWorkbook.Worksheets(€œSheet2€³).Sort.SortF ields.Add
Key:=ActiveCell, _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(€œSheet2€³).Sort
..SetRange ActiveCell.Range(€œA1:A14€³)
..Header = xlNo
..MatchCase = False
..Orientation = xlTopToBottom
..SortMethod = xlPinYin
..Apply
End With
End Sub


i used this code .SetRange ActiveCell.Range(Selection,
Selection.End(xlDown)) instead of .SetRange ActiveCell.Range(€œA1:A14€³)
but was not able to make my macro dynamic how can i make my macro
dynamic?
make macro dynamic help!

Per Jessen[_2_]

vba dynamic
 
Hi

Try this:

SetRange Range(selection,Range(selection).end(xldown))

Regards,
Per

On 12 Feb., 01:32, danial mansoor wrote:
hi experts!
i ve this macro but i want to make it dynamic how can i do it?

Sub Macro1()
€˜
€˜ Macro1 Macro
€˜
€˜finalrow = Cells(Rows.Count, 1).End(xlUp).Value
ActiveWorkbook.Worksheets(€œSheet2€³).Sort.SortF ields.Clear
ActiveWorkbook.Worksheets(€œSheet2€³).Sort.SortF ields.Add
Key:=ActiveCell, _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(€œSheet2€³).Sort
.SetRange ActiveCell.Range(€œA1:A14€³)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

i used this code .SetRange ActiveCell.Range(Selection,
Selection.End(xlDown)) instead of .SetRange ActiveCell.Range(€œA1:A14€³)
but was not able to make my macro dynamic how can i make my macro
dynamic?
make macro dynamic help!




All times are GMT +1. The time now is 06:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com