Question

In: Computer Science

(EXCEL vba) Problem: Trying to remove the entire row if the year is before 2019. Current...

(EXCEL vba) Problem: Trying to remove the entire row if the year is before 2019.

Current code: Range("B2").Select
Do Until ActiveCell.Value = ""

If ActiveCell.Value < 2019 Then ActiveCell.EntireRow.Delete

Else
ActiveCell.Offset(1, 0).Select

End If Loop

Code Problem: My data sets can be 1000's of rows so checking every cell is very slow.

Since the data is always in order, all I need to do is find the first entry <2019 and then select xlDown and delete everything, but I don't know how to find that cell and make it the active cell.

Solutions

Expert Solution

In case of any query do comment. Please rate answer as well. Thanks

Code:

Sub RemoveRowBefore2019()
Dim LastRow As Integer
Range("B2").Select
Do Until ActiveCell.Value = ""
    If ActiveCell.Value < 2019 Then
        ' to select the last row
        LastRow = Cells(Rows.Count, "B").End(xlUp).Row
        'then select the range from current cell till last cell and call delete on Range
        Range(ActiveCell, ActiveCell.Offset(LastRow, 0)).EntireRow.Delete
        'To exit from do loop after this
        Exit Do
    Else
        ActiveCell.Offset(1, 0).Select
    End If
Loop
End Sub

Lets' say you have ranges from B2 till B600 and year less than 2019 is at B274.

Now see the output: All rows before 2019 are removed:


Related Solutions

Problem #1 Facts: (Question 1 - Question 5) On December 31, 2019, of the current year...
Problem #1 Facts: (Question 1 - Question 5) On December 31, 2019, of the current year Smith Enterprises physically counted $1,500,000 of inventory. The following additional information is also available: Smith Enterprises sold goods for $250,000 to Julia Corp. Smith Enterprises had originally purchased the goods for $175,000. The order was shipped to Julia FOB shipping point on December 28, 2019 and arrived at Julia's facility on January 2, 2020. Smith purchased goods costing $40,000 from vendor Lemon Drop Company....
You are trying to value “A2M” share today (End of June 2019). Assume the current price...
You are trying to value “A2M” share today (End of June 2019). Assume the current price of the share in the stock market is $17.15 and that you would like to hold the investment for 4 years. Assume that “A2M” will pay its first dividend ($0.5 AUD) one year from now. The total dividend will be paid as a lump sum (at once). After this you also estimate that the dividends will grow respectively at 30%, 25% per year. After...
Solve the problem in EXCEL You are considering issuing two types of bonds. The current yield...
Solve the problem in EXCEL You are considering issuing two types of bonds. The current yield to maturity on similar bonds is 4% annually. Both bonds have a face value of $1000 and will pay annual coupons. Bond A has a maturity of 10 years and bond B has a maturity of 20 years. You want to compute the price of both bonds at the prevailing interest rate and see what happens to the price of the bonds as the...
Comprehensive Budgeting Problem To be completed using Excel. The Highlander Corporation Balance Sheet December 31, 2019...
Comprehensive Budgeting Problem To be completed using Excel. The Highlander Corporation Balance Sheet December 31, 2019 Assets Cash            $        6,595 Accounts Receivable                    10,000 Finished Goods (575 units x $7.00 per unit                      4,025 Raw Materials (2,760 square inches @ $0.50 per square inch)                      1,380 Plant and Equipment                $     60,000 Less: Accumulated Depreciation                       15,000                          45,000               Total Assets                     67,000 Liabilities Trade Accounts Payable                        9,000                      9,000 Stockholders’ Equity Common Stock                        33,000 Retained...
Budgets are developed months before the end of the current year and are best guess estimates...
Budgets are developed months before the end of the current year and are best guess estimates of future performance. What do you think might be some pitfalls of budgeting, and how can they be avoided?
Budgets are developed months before the end of the current year and are best guess estimates...
Budgets are developed months before the end of the current year and are best guess estimates of future performance. What do you think might be some pitfalls of budgeting, and how can they be avoided?
On December 31, 2019, of the current year Company A physically counted $1,500,000 of inventory. The...
On December 31, 2019, of the current year Company A physically counted $1,500,000 of inventory. The following additional information is also available: Company A sold goods for $250,000 to Dog Enterprise. Company A had originally purchased the goods for $175,000. The order was shipped to Dog Enterprise FOB shipping point on December 28, 2019 and arrived at Dog Enterprise facility on January 2, 2020. Question 1: Does Company A adjust or not adjust the physical count for the in-transit goods?...
Billco Corporation expects earnings before interest and taxes to be $450,000 for the current tax year....
Billco Corporation expects earnings before interest and taxes to be $450,000 for the current tax year. Using the U.S. corporate flat tax rate of 21%, compute the Billco’s earnings available for common stockholders if the firm pays $25,000 in interest versus $25,000 in preferred stock dividends. Answers: A.) $371,000; $347,000 B.) $357,080; $357,080 C.) $335,750; $330,500 D.) $376,040; $352,040
Erin, a single taxpayer, has a taxable income of $168,000 in the current year before considering...
Erin, a single taxpayer, has a taxable income of $168,000 in the current year before considering the following capital gains and losses: Short-term capital gain $    3,000 Long-term capital gain 22,000 Unrecaptured Section 1250 gain 14,000 In addition, Erin has an $8,000 long-term capital loss carryover from last year. What are the effects of these transactions on Erin’s taxable income and her income tax liability?
Rick and Maria had been married for 20 years before their divorce in the current year....
Rick and Maria had been married for 20 years before their divorce in the current year. At that time, they made the usual property settlement: Maria got the house, the van, and the cat; Rick got the mortgage, the Ford, and the dog. Other property was divided equally with the exception of the following: At the time of their divorce, Maria had instituted a number of lawsuits against various fast-food chains for infringement of her patent on an automated burrito-stuffing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT