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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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