how does xlup -1 works in vba?

jaik22

Board Regular
Joined
Sep 23, 2016
Messages
102
Code:
Sub reva()
Dim LastRowColumnA As Long: LastRowColumnA = Sheets("Working Other Purchases").Cells(Rows.Count, 1).End(xlUp).Row




   ActiveSheet.Range("A1:AV" & LastRowColumnA).AutoFilter Field:=12, Criteria1:="=*Rate*", Operator:=xlFilterValues




    ActiveSheet.Range("A1:AV" & LastRowColumnA).AutoFilter Field:=10, Criteria1:="="
   Range("J10000", Cells(Rows.Count, "J").End(xlUp).Offset(-1)).Select


    
    ActiveCell.FormulaR1C1 = "Rate"
    Selection.FillDown
End Sub

Hi guys, I am trying to filter 12th column *Rate* and filter 10th column with "=".
Then I am trying to fill up the 10th column's with "Rate".
Code above is what I tried to put rate in the 10th column, but xlup function does not work properly

does anyone has Idea abnout this?

Thank you!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Consider:

Code:
Sub reva()    
    With Sheets("Working Other Purchases").Cells(1).CurrentRegion
        .AutoFilter Field:=12, Criteria1:="=*Rate*"
        .AutoFilter Field:=10, Criteria1:="="
        .Columns(10).SpecialCells(xlCellTypeVisible).Value = "Rate"
    End With
    
End Sub
 
Upvote 0
Hey Wigi, Thanks for your support, but If I run your code, it aslo changes the column name.
Is there any way to not include column name using SpecialCells(xlCellTypeVisible)?

Thanks!
 
Last edited:
Upvote 0
Code:
   Range("J10000", Cells(Rows.Count, "J").End(xlUp).Offset(-1)).Select
[/QUOTE]
Got this line working though it will fail if there is no data visible in column J. Besides, is it intentional that you want to select from row 10000 and down/up to the last row?:
[CODE]Range("J10000", Range("J" & Rows.Count).End(xlUp).Offset(-1, 0)).Select
If you want to select the whole range in the filtered table, use this instead:
Code:
Range("J2", Range("J" & Rows.Count).End(xlUp)).Select
 
Upvote 0
You can use Offset(1) to go 1 row down.
 
Upvote 0
You can use Offset(1) to go 1 row down.

Code:
Sub reva3()    With Sheets("Working Other Purchases").Cells(1).CurrentRegion
        .AutoFilter Field:=12, Criteria1:="=*Rate*"
        .AutoFilter Field:=10, Criteria1:="="
        .Columns(10).SpecialCells(xlCellTypeVisible).Offset(1) = "Rate"
    End With
    
End Sub

If I do something like that It only fills up the one of the column, am I using offset correctly?
 
Upvote 0
Does this do what you need?

Code:
Sub reva3()

    With Sheets("Working Other Purchases").Cells(1).CurrentRegion
        .AutoFilter Field:=12, Criteria1:="=*Rate*"
        .AutoFilter Field:=10, Criteria1:="="
        .Columns(10).Offset(1).SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Offset(1) = "Rate"
    End With


End Sub
 
Upvote 0
Thank you so much for your help.

If I run that code, column I filled with rate instead filling J.
I believe second offset is causing the problem. But, if I only run first one I get one more rate in the column.

Is there any way to solve this?

Thank you!
 
Upvote 0
Yes the second Offset is the issue.
You should resize the Currentregion:

Code:
With Sheets("Working Other Purchases").Cells(1).CurrentRegion
    .Resize(.Rows.Count - 1).Offset ....
End With

This could shifts the currentregion 1 row down (offset) but also removes the extra line that is induced by the offset (see the -1)
 
Upvote 0

Forum statistics

Threads
1,222,688
Messages
6,167,643
Members
452,127
Latest member
jayneecm

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