Delete Rows and Columns until specific range

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Delete Rows and Columns until specific range



I have an Excel workbook in which I search for a date in the heading using .Find.


.Find



For example if it is found in RANGE("C3") then it should remove rows above and columns before it.


RANGE("C3")



Please help me write the VBA code to perform this operation.


Dim WSD As Worksheet
Set WSD = Worksheets("report")
Dim MyRange As Range
Set MyRange = WSD.Range("A:AZ")
Set R = MyRange.Find("Date", LookIn:=xlValues)
Debug.Print R.Address





So for all intents and purposes you are shifting Date to A1 ...?
– Jeeped
Aug 10 at 12:03





yes. i want my header to start from 1 row and 1 column
– Prayag
Aug 10 at 12:06





my macro which contains many modules is based on A1. rest all other are completed only for one sheet my progress is halted.
– Prayag
Aug 10 at 12:10





2 Answers
2



Try,


dim MyRange as range

with Worksheets("report")
Set MyRange = .Range("A:AZ").Find("Date", LookIn:=xlValues)
if not MyRange is nothing then
if MyRange.column > 1 then
.cells(1, 1).resize(1, MyRange.column -1).entirecolumn.delete
end if
if MyRange.row> 1 then
.cells(1, 1).resize(MyRange.row-1, 1 ).entirerow.delete
end if
end if
end with





Thank you so much @Jeeped. i really appreciate your support. it did solve my problem.
– Prayag
Aug 10 at 12:14




another way:


Dim MyRange As Range
With Worksheets("report")
Set MyRange = .Range("A:AZ").Find("Date", LookIn:=xlValues)
If Not MyRange Is Nothing Then MyRange.Resize(.UsedRange.Rows.Count + MyRange.Row, .UsedRange.Columns.Count + MyRange.Column).Cut Destination:=.Range("A1")
End With



Or


Dim MyRange As Range
With Worksheets("report")
Set MyRange = .Range("A:AZ").Find("Date", LookIn:=xlValues)
If Not MyRange Is Nothing Then
.Rows(1).Insert
.Columns(1).Insert
With .Range("A1", MyRange)
.Resize(, .Columns.Count - 1).EntireColumn.Delete
.Resize(.Rows.Count - 1).EntireRow.Delete
End With
End If
End With






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard