• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

HIDE/UNHIDE COLUMNS AND ADD SUBTOTALS|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / HIDE/UNHIDE COLUMNS AND ADD SUBTOTALS|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosHIDE/UNHIDE COLUMNS AND ADD SUBTOTA…
sp_PrintTopic sp_TopicIcon
HIDE/UNHIDE COLUMNS AND ADD SUBTOTALS
Avatar
Amien Attwood
Cape Town
Member
Members
Level 0
Forum Posts: 18
Member Since:
May 8, 2018
sp_UserOfflineSmall Offline
1
January 20, 2021 - 2:57 am
sp_Permalink sp_Print

Dear Mynda/Purfleet or anyone that may assist

 

See attached document. There are two sheets, namely Data and Criteria.  Please look at my Criteria and kindly assist with writing some VBA Code to make this work.

I know I can simply run a Pivot Table to make this work but I do not want to overwrite the existing data with new data then refresh the Pivot whereas I can just run a Macro from my Personal Workbook and saved on the ribbon.

Regards,

Amien

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
January 21, 2021 - 1:10 pm
sp_Permalink sp_Print

Hi Amien,

A pivot from that data will never work, structure is simply wrong.

Mixing source data with a visual is a bad idea, any report that will be needed will need a significant effort.

Best way is to use power query or even vba to reorganize data into a normal tabular structure, this will give you much more flexibility to build many more different reports based on the same data.

Avatar
Amien Attwood
Cape Town
Member
Members
Level 0
Forum Posts: 18
Member Since:
May 8, 2018
sp_UserOfflineSmall Offline
3
January 21, 2021 - 7:37 pm
sp_Permalink sp_Print

Hi Catalin

Thanks for the answer. However, I am asking for some VBA code and the steps I need is in Sheet 2 of my workbook.

Thanks.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
January 22, 2021 - 2:39 am
sp_Permalink sp_Print

Try these codes:

Sub HideUnhide()
Dim i As Long, HideRng As Range, HideStatus As Boolean
i = 1
Do Until Len(ActiveSheet.Cells(1, i).Value) = 0
If ActiveSheet.Cells(1, i).Value Like "??? ####" Then
If HideRng Is Nothing Then
Set HideRng = ActiveSheet.Cells(1, i)
Else
Set HideRng = Union(HideRng, ActiveSheet.Cells(1, i))
End If

End If
i = i + 1
Loop

'hide or unhide
HideStatus = HideRng.Cells(1).EntireColumn.Hidden
HideRng.EntireColumn.Hidden = Not HideStatus

End Sub

Sub AddSubtotals()
Dim i As Long, DataRng As Range, LastRow As Long
i = 1
LastRow = ActiveSheet.Cells.Find("*", ActiveSheet.Cells(1), , , xlByRows, xlPrevious).Row
Do Until Len(ActiveSheet.Cells(1, i).Value) = 0
If ActiveSheet.Cells(1, i).Value Like "FY ####" Then
ActiveSheet.Cells(LastRow + 1, i).FormulaR1C1 = "=SUM(R[-" & LastRow - 1 & "]C:R[-1]C)"
End If
i = i + 1
Loop
End Sub

 

For freezing rows, i suggest starting the code recorder, you will get the base code needed.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
Jessica Stewart: 205
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
stuart burge
Bruce Tang Nian
Scot C
Othman AL MUTAIRI
Misael Gutierrez Sr.
Attif Ihsan
Kieran Fee
Murat Hasanoglu
Brett Dryland
Saeed Aldousari
Forum Stats:
Groups: 3
Forums: 24
Topics: 6223
Posts: 27295

 

Member Stats:
Guest Posters: 49
Members: 31920
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.