VBA code to select data till a particular cell value

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello Guys

Sub Test()
Sheets("Kotak Bank Book").Select
Cells.Select
Selection.UnMerge
Rows("1:5").Select
Selection.Delete Shift:=xlUp
Range("B1").Select
End Sub

This sheet is sent to me by a client. I need to clean and arrange the sheet to my requirement which I have been doing it manually till now. Since the working steps are the same for every sheet and every time I have decided to try and write a code step by step.
This code will always select the first 5 rows and delete it. I want the rows above the headings to be deleted each time. So, I need the code to select the rows above the column with the “date” heading and delete them. At times the headings may be in the 3rd row or in the 7th row in different data. So I want a code to work accordingly.

TALLY.xlsx
ABCDEFGHI
1Test Multiple Ledgers
2Kotak Bank Book
3
4
51-Jul-2021 to 2-Jul-2021
6DateParticularsVch TypeVch No.DebitCredit
701-07-2021CrOpening Balance15000.00
801-07-2021Cr(as per details)Receipt4040.00
9Sunday1015.00 Cr
10Monday2025.00 Cr
11Tuesday1000.50 Cr
12Round Off0.50 Dr
1302-07-2021Dr(as per details)Payment10041001.00
14January100.00 Dr
15February200.00 Dr
16March300.00 Dr
17April400.00 Dr
18Round Off1.00 Dr
1902-07-2021CrCashContra10082000.00
2002-07-2021DrCashContra100925000.00
Bank Ledger
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
How about
VBA Code:
Sub Rajesh()
   Dim Fnd As Range
   
   With Sheets("Kotak Bank Book")
      .UsedRange.UnMerge
      Set Fnd = .Range("A:A").Find("Date", , , xlPart, xlByRows, xlNext, False, , False)
      If Not Fnd Is Nothing And Fnd.Row > 1 Then .Rows("1:" & Fnd.Row - 1).Delete
   End With
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub Rajesh()
   Dim Fnd As Range
  
   With Sheets("Kotak Bank Book")
      .UsedRange.UnMerge
      Set Fnd = .Range("A:A").Find("Date", , , xlPart, xlByRows, xlNext, False, , False)
      If Not Fnd Is Nothing And Fnd.Row > 1 Then .Rows("1:" & Fnd.Row - 1).Delete
   End With
End Sub
Perfect Fluff. Thanks. Please be in touch. I have a long code to write which will help me to finish my one hour work in less than a minute. I will post a new post for the next question as soon as I get stuck once again.?
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,569
Members
449,038
Latest member
Guest1337

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