Using offset In vba

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
Range(Replace("B#:D#,M#:W#,AH#,AK#:FE#", "#", Target.Row)).ClearContents
      ActiveWorkbook.Worksheets("EMPLOYEE LIST").AutoFilter.Sort.SortFields.Clear
      ActiveWorkbook.Worksheets("EMPLOYEE LIST").AutoFilter.Sort.SortFields.Add Key _
        :=Range("A1:A1000"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("EMPLOYEE LIST").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
End With

the above code is part of a double click on range"A2:A1000") when I double click on cell A16 then Range("B16:D16,M16:W16,AH16,AK16:FE16") values are deleted. I want to add the function to also include offset (1 , 0) of BJ#:FE#, 1 row down from BJ#:FE# so using the above if A16 is double clicked I would like range ("B16:D16,M16:W16,AH16,AK16:FE16",BJ17:FE17) delete value

if A30 is double clicked

then range would be ("B30:D30,M30:W30,AH30,AK30:FE30",BJ31:FE31).ClearContents

any help is greatly appreciated. Thanks :)
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try changing the first line to
VBA Code:
Intersect(Target.EntireRow.Resize(2),Range("B:D,M:W,AH:AH,AK:FE")).ClearContents
 
Upvote 0
My take on this
VBA Code:
Range(Replace(Replace("B#:D#,M#:W#,AH#,AK#:FE#,BJ¬:FE¬", "#", Target.Row), "¬", Target.Offset(1).Row)).ClearContents
 
Upvote 0
Solution

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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