Excel VBA图表最大刻度误差
这段代码有两个问题需要帮助,我是vba新手,不确定问题的原因是什么 第一个问题是,当Excel VBA图表最大刻度误差,vba,excel,charts,axis,Vba,Excel,Charts,Axis,这段代码有两个问题需要帮助,我是vba新手,不确定问题的原因是什么 第一个问题是,当Me.Range(“L7”)=Format(Me.Range(“C4”)…)被格式化时,它会将日期放在美式格式“mm/dd/yyyy”中。但是,下一行Me.Range(“L8”)是否被转换为正确的“dd/mm/yyyy”格式 第二个问题是,当我更改图表的最大轴时,我会得到一个类型不匹配错误,而最小轴比例的更改工作得很好 谢谢你的帮助 Private Sub CommandButton1_Click() answe
Me.Range(“L7”)=Format(Me.Range(“C4”)…)
被格式化时,它会将日期放在美式格式“mm/dd/yyyy”中。但是,下一行Me.Range(“L8”)是否被转换为正确的“dd/mm/yyyy”格式
第二个问题是,当我更改图表的最大轴时,我会得到一个类型不匹配错误,而最小轴比例的更改工作得很好
谢谢你的帮助
Private Sub CommandButton1_Click()
answer = MsgBox("This will prepare the workbook for the next month, are you sure?", vbYesNo)
If answer = vbNo Then Exit Sub
Range("c34") = "=DATE($B$2,$A$2,A34)" 'enters formula into cell c34
Range("a2") = Month(Date) - 1 'changes month to last month
Range("a3") = Year(Date)
If Month(Date) - 1 <> Month(Range("c34")) Then
Range("C34").Clear 'checks if last date in column is in same month, if not, clear
End If
myLR = ThisWorkbook.Sheets("Data Input").Cells(Rows.Count, 3).End(xlUp).Row 'grabs date in last row
Me.Range("L7") = Format(Me.Range("c4"), "dd/mm/yyyy") 'gets start date of month and formats it
Me.Range("L8") = Format(Me.Cells(myLR, 3).Value, "dd/mm/yyyy") 'gets last date of month and formats it
Range("K7") = "First Day of Month"
Range("K8") = "Last Day of Month"
'Chart section
Sheets("Site 5").Select
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.Axes(xlCategory).MinimumScale = Sheets("data input").Range("L7")
ActiveChart.Axes(xlCategory).MaximumScale = Sheets("data input").Range("L8")
ActiveChart.Axes(xlCategory).Select
Selection.TickLabels.NumberFormat = "d/mm/yyyy"
End Sub
Private子命令按钮1\u单击()
answer=MsgBox(“这将为下个月准备工作簿,您确定吗?”,vbYesNo)
如果答案=vbNo,则退出Sub
范围(“c34”)=“=日期($B$2,$A$2,A34)”将公式输入单元格c34
范围(“a2”)=月份(日期)-1'与上月的变化
范围(“a3”)=年份(日期)
如果月份(日期)-1个月(范围(“c34”)),则
范围(“C34”).Clear”检查列中的最后日期是否在同一个月,如果不是,则清除
如果结束
myLR=ThisWorkbook.Sheets(“数据输入”).Cells(Rows.Count,3)。End(xlUp)。行获取最后一行中的日期
Me.Range(“L7”)=Format(Me.Range(“c4”),“dd/mm/yyyy”)获取月份的开始日期并对其进行格式化
Me.Range(“L8”)=Format(Me.Cells(myLR,3).Value,“dd/mm/yyyy”)获取月份的最后日期并对其进行格式化
范围(“K7”)=“月的第一天”
范围(“K8”)=“月的最后一天”
'图表部分
图纸(“现场5”)。选择
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.Axes(xlCategory).MinimumScale=表格(“数据输入”).范围(“L7”)
ActiveChart.Axes(xlCategory).MaximumScale=Sheets(“数据输入”).Range(“L8”)
ActiveChart.Axes(xlCategory)。选择
Selection.ticklables.NumberFormat=“d/mm/yyyy”
端接头
不适合通过格式函数更改单元格的值。
最好通过NumberFormatLocal更改单元格的格式
Private Sub CommandButton1_Click()
answer = MsgBox("This will prepare the workbook for the next month, are you sure?", vbYesNo)
If answer = vbNo Then Exit Sub
Range("c34") = "=DATE($B$2,$A$2,A34)" 'enters formula into cell c34
Range("a2") = Month(Date) - 1 'changes month to last month
Range("a3") = Year(Date)
If Month(Date) - 1 <> Month(Range("c34")) Then
Range("C34").Clear 'checks if last date in column is in same month, if not, clear
End If
myLR = ThisWorkbook.Sheets("Data Input").Cells(Rows.Count, 3).End(xlUp).Row 'grabs date in last row
'Me.Range("L7") = Format(Me.Range("c4"), "dd/mm/yyyy") 'gets start date of month and formats it
Me.Range("L7") = Me.Range("c4")
Me.Range("L7").NumberFormatLocal = "dd/mm/yyyy"
'Me.Range("L8") = Format(Me.Cells(myLR, 3).Value, "dd/mm/yyyy") 'gets last date of month and formats it
Me.Range("L8") = Me.Cells(myLR, 3).Value
Me.Range("L8").NumberFormatLocal = "dd/mm/yyyy"
Range("K7") = "First Day of Month"
Range("K8") = "Last Day of Month"
'Chart section
Sheets("Site 5").Select
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.Axes(xlCategory).MinimumScale = Sheets("data input").Range("L7")
ActiveChart.Axes(xlCategory).MaximumScale = Sheets("data input").Range("L8")
ActiveChart.Axes(xlCategory).Select
Selection.TickLabels.NumberFormat = "d/mm/yyyy"
End Sub
Private子命令按钮1\u单击()
answer=MsgBox(“这将为下个月准备工作簿,您确定吗?”,vbYesNo)
如果答案=vbNo,则退出Sub
范围(“c34”)=“=日期($B$2,$A$2,A34)”将公式输入单元格c34
范围(“a2”)=月份(日期)-1'与上月的变化
范围(“a3”)=年份(日期)
如果月份(日期)-1个月(范围(“c34”)),则
范围(“C34”).Clear”检查列中的最后日期是否在同一个月,如果不是,则清除
如果结束
myLR=ThisWorkbook.Sheets(“数据输入”).Cells(Rows.Count,3)。End(xlUp)。行获取最后一行中的日期
“Me.Range(“L7”)=Format(Me.Range(“c4”),“dd/mm/yyyy”)获取月份的开始日期并对其进行格式化
Me.Range(“L7”)=Me.Range(“c4”)
Me.Range(“L7”).NumberFormatLocal=“dd/mm/yyyy”
'Me.Range(“L8”)=Format(Me.Cells(myLR,3).Value,“dd/mm/yyyy”)'获取月份的最后日期并对其进行格式化
Me.Range(“L8”)=Me.Cells(myLR,3).值
Me.Range(“L8”).NumberFormatLocal=“dd/mm/yyyy”
范围(“K7”)=“月的第一天”
范围(“K8”)=“月的最后一天”
'图表部分
图纸(“现场5”)。选择
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.Axes(xlCategory).MinimumScale=表格(“数据输入”).范围(“L7”)
ActiveChart.Axes(xlCategory).MaximumScale=Sheets(“数据输入”).Range(“L8”)
ActiveChart.Axes(xlCategory)。选择
Selection.ticklables.NumberFormat=“d/mm/yyyy”
端接头