Excel VBA Macro - Data out of range column reduction

ShaneB614

New Member
Joined
Jun 17, 2020
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
I have a calculation sheet with live formulas that contains data with column headings titled 2020-2028 (9 columns) (B2:B10)

On an input sheet, I have START and END dates in two different cells (A1,A2)

With that said, I would like a VBA macro that is able to look at the START and END dates on the input sheet, and based on their presence in the range defined by (A1,A2), delete the columns that are out of range on the calculation sheet.

Theoretically, only year columns within the START and END Year range will be left on my calculation sheet.

Any feedback or further direction is greatly appreciated.
 
Best solution is, don't use merged cells, they are nothing but trouble. Especially where VBA is concerned.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I think the easiest solution would be to just enter the dates in row 2 twice as shown below. Then the same code woould work.

Book1
ABCDEFGHIJKLMNOPQRS
1
2202020202021202120222022202320232024202420252025202620262027202720282028
354%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
454%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
554%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
654%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
754%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
854%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
954%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
1054%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
1154%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
1254%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
1354%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
1454%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
1554%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
1654%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
1754%34%14%-6%-26%-46%-66%-86%25%25%25%25%25%25%25%25%25%25%
Sheet1
 
Upvote 0
You might want to consider this. Unmerge your cells in your database where you do your calculations and maneuver your columns and rows. Then once you have created what you want for output, do your cell merges or whatever other formatting you desire for your reports. But if you plan to use vba frequently for data manipulation and calculations, I would strongly recomend the minimum of cosmetic formatting because it is a detriment to efficient vba coding. Save the formatting for your output reports, which can also be done with vba after all the data manipulations and calculations are done.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
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