Using VBA to hide columns doesn't hide them the same as "hide"

Jimbomack

New Member
Joined
Aug 27, 2020
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a worksheet that contains data in columns A through ZY. I have the worksheet window split between columns M and N. All columns from N through ZY are titled with dates. I want to use a macro to hide certain columns from N through to a user selected column that is based on the date title. The user enters a date in a cell and runs the Macro and all columns from N through to that dated column are then hidden. The reason for hiding these columns is so that when the user drags from a column to the left of N, over the hidden columns, the hidden columns remain hidden, unlike if the window was simply split at column M-N.
When I "hide" the columns using the traditional drop down in Excel, it works fine as desired. Those columns never show up, regardless of where I drag my mouse.

The Macro below works like a charm in hiding the columns, but when I drag across the boundary over the hidden columns, the hidden columns reappear. It's like the VBA code for hiding columns is not the same as the basic "Hide" command found in the drop down in Excel. I've read/proven that "Veryhidden" does not work for columns.
What am I doing wrong?
Thx

Sub hidecolumns()
Dim X As Variant
X = Range("j2").Value
Columns("N").Columns(X).Select
Selection.Columns.Hidden = True
End Sub
 
You're welcome & thanks for the feedback.
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

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