VBA rows selection leads to "selection wrong number of arguments or invalid property assignment"

askofa

New Member
Joined
May 4, 2020
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
Hello!


I'm trying to write a simple macro that will delete few rows, than sort by values from one of columns and than delete few rows below some value.

I am using the strings of the code just strictly from "record macro" function.

It does have codes like

rows("1:6").Select

or

Columns("H:H").Select

But when I try to apply the macro with those strings on another excel file, VBA give error "selection wrong number of arguments or invalid property assignment" in that place!


I've tried everything! What's wrong? Please, help me)


Here is an example of whole macro:



Sub sort4()
'
' sort4 ??????
'

'
Dim zz As String
zz = ActiveSheet.Name
rows("1:6").Select
Selection.Delete Shift:=xlUp
Range("I1").Select
ActiveCell.FormulaR1C1 = "diff"
Columns("H:H").Select
ActiveWorkbook.Worksheets(zz).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(zz).Sort.SortFields.Add Key:= _
Range("H1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets(zz).Sort
.SetRange Range("A2:I19501")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
rows("1527:19495").Select
Selection.Delete Shift:=xlUp
Range("Q1519").Select
Range("I2").Select
ActiveCell.FormulaR1C1 = "=RC[-7]-RC[-4]"
Range("I2").Select
Selection.AutoFill Destination:=Range("I2:I1526"), Type:=xlFillDefault
Range("I2:I1526").Select
ActiveSheet.Calculate
ActiveWorkbook.Worksheets(zz).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(zz).Sort.SortFields.Add Key:= _
Range("I2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets(zz).Sort
.SetRange Range("A2:I1526")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub



Thank you!



Kat
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Watch MrExcel Video

Forum statistics

Threads
1,113,836
Messages
5,544,596
Members
410,624
Latest member
smartsanjiv64
Top