This is my first time asking a question, so please bear with me.
I have made a macro to hide columns in a named range based on a criteria using FOR-NEXT loop. The result always displays 2 columns.
With the resulting 2 columns, I make calculations.
I am facing problem to get the column number using vba of the resulting displayed columns and use them in the offset formula to make the calculations.
Can anybody help? Thanks
Public Sub Custom_Report_Monthly()
On Error Resume Next
If Len(Range("Rpt_Type_M").Value) < 1 Then
MsgBox "Select Report Type"
GoTo ExitSub
ElseIf Len(Range("Select_Month").Value) < 1 Then
MsgBox "Select Month"
GoTo ExitSub
End If
ActiveSheet.Range("D_columns").EntireColumn.Hidden = True
If Range("Rpt_Type_M").Value = "Quantity" Then
For Each c In Range("Titles")
If c.Value = "Quantity" Then
c.Columns.EntireColumn.Hidden = False
End If
Next
ElseIf Range("Rpt_Type_M").Value = "Sales" Then
For Each c In Range("Titles")
If c.Value = "Sales" Then
c.Columns.EntireColumn.Hidden = False
End If
Next
ElseIf Range("Rpt_Type_M").Value = "Cost" Then
For Each c In Range("Titles")
If c.Value = "Cost" Then
c.Columns.EntireColumn.Hidden = False
End If
Next
ElseIf Range("Rpt_Type_M").Value = "Sales+Cost" Then
For Each c In Range("Titles")
If c.Value = "Sales" Then
c.Columns.EntireColumn.Hidden = False
End If
Next
For Each c In Range("Titles")
If c.Value = "Cost" Then
c.Columns.EntireColumn.Hidden = False
End If
Next
End If
For Each c In Range("P_Months")
If Month(c.Value) <> Range("Select_Month_Num").Value Then
c.Columns.EntireColumn.Hidden = True
End If
Next
For Each col In Range("D_columns") ' **this is the block where i am having problem**
If col.EntireColumn.Hidden = False Then
MsgBox (Range("col").Column)
End If
Next
Call Hide_Count_Columns
ExitSub:
End Sub