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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,223,703
Messages
6,173,973
Members
452,540
Latest member
haasro02

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