Find min and max dates to paste in Axis Options

bastian18

New Member
Joined
Aug 15, 2018
Messages
22
Hello.


I have a code to find min and max dates in Range("A") and Range("A2") and a MsgBox displaying min date(in format number) and another MsgBox displaying min date (in format number).
This is my code and works fine:
Code:
Sub minmaxdate()
Dim rng As Range
    Dim ws As Worksheet
    Dim ch As Chart
    Dim a As Range
    Dim b As Range 
    
    Set ws = Worksheets("qry_creategantt")
Set a = Range("A2:A" & Rows.Count)
        With a
            .Application.WorksheetFunction.Min (a)
        End With
        MsgBox Application.WorksheetFunction.Min(a)
        
     Set b = Range("b2:b" & Rows.Count)
        With b
            .Application.WorksheetFunction.Max (b)        
        End With
        MsgBox Application.WorksheetFunction.Max(b)
End Sub

However, instead of Msgboxes I need with my code doing this:


1. Find min date value, convert to number, go to Axis Option and paste value in Fixed Min
2. Find max date value, convert to number, go to Axis Option and paste value in Fixed Max

How can I modify my code to do that?

PD. ch is a variable I am using to create a Gantt chart.
Thanks
 

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.
Please, see that in Range("A") and Range("A2")
the correct line must be Range("B") and Range("B2").
Cheers

 
Upvote 0
Hello.
Finally d, I found the code lines to modified my code.:)
This is my code:

Code:
Sub [COLOR=#333333]minmaxdate()[/COLOR]
     
     Dim a, b As Range
          Set a = Range("A2:A" & Rows.Count)
               With a
                    .Application.WorksheetFunction.Min (a)
               End With
    
          Set b = Range("b2:b" & Rows.Count)
               With b
                   .Application.WorksheetFunction.Max (b) '
          End With
    
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.Axes(xlValue).Select
    
    ActiveChart.Axes(xlValue).MinimumScale = ActiveChart.Application.WorksheetFunction.Min(a)
          
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.Axes(xlValue).Select


End Sub

How can I avoid using in my code?:confused:
Code:
ActiveSheet ActiveChart Activate ("Chart X")

Also, I would appreciate any advice to write minimal lines in my code.

Cheers
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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