5,2),1)这样会显示为1980-1-1,然后可以随意设置成相应的日期格式。
034.请帮忙解释一个公式
=LEFT(A1,(SEARCHB("?",A1)-1)/2)这是我在站内过去的帖子里看到的一个公式,用于提取前文后数中的文字部分,非常好用。请教这个公式中最后两步的意义是什么?另外,当A1是“1234个”的格式时,当如何提取其中的文字呢?
解答:1、公式的含义是:查找第一个半角字符出现的位置[SEARCHB("?",A1)],减去1后除以2,就是文字的字符数目,将其提取出来。
2、=RIGHT(A1,LENB(A1)-LEN(A1))
035.关于宏和程序
我现在已经用excel编了一个较完整的程序,并且能够给源程序加密码,实现"工程不可见",但是我发现在vba编辑环境里还能看到我的大部分宏,虽然说不能编辑,但能运行,请问如何隐藏起来。
解答:不用模块函数,重写成类或放到workbook中,或在程序中直接将菜单宏隐藏。或者:新建类,然后将模块中的程序拷贝到类,提示:找不到宏。
又问:我现在已经能做到屏蔽调alt+F11键了,虽然不能看到我的宏程序,但是依然可以运行我的宏,请高手做答,如何隐藏起我的宏。
解答:在宏的声明前加Private。
036.请教多条件求和的问题
大家好,我是个新手,想向大家请教指定多条件求和的函数公式。
譬如,有一张工作表有4列标题:品名,数量,日期,签收人。
若我想求,符合条件为:品名为A,日期为Y,签收人为B的数量之和。
该用那个函数公式?
解答:=IF(A2="a",IF(B2="03.10.22",COUNTIF(D:D,D2),"时间无"),"无")
A列品名,B列日期,C列数量,D列签收人用if 嵌套。
或者:数组公式
{=sum((a1:a100=品名)*(c1:c100=日期)(d1:d100=签收人)*(B1:B100))}
也可以:{=SUM((($A$1:$A$100)="a")*(($B$1:$B$100)="03.10.22"))}
037.请教关于星期的计算?
如何通过输入一个日期:2003-10-20即可得到该天在本年度的第几个星期?
解答:使用 WEEKNUM 函数。
如:=WEEKNUM(A1)
=WEEKNUM(TODAY())
或者:日期在a1
=INT((A1-DATE(YEAR(A1),1,0)+WEEKDAY(DATE(YEAR(A1),1,0),1)+7-WEEKDAY(A1,1))/7)
也可以用VBA:
'under the iso standard, a week always begins on a monday, and ends on a sunday.
'the first week of a year is that week which contains the first thursday of the year,
'or, equivalently, contains jan-4.
'
public function isoweeknum(anydate as date, _
optional whichformat as variant) as integer
'
' whichformat: missing or <> 2 then returns week number,
' = 2 then yyww
'
dim thisyear as integer
dim previousyearstart as date
dim thisyearstart as date
dim nextyearstart as date
dim yearnum as integer
thisyear = year(anydate)
thisyearstart = yearstart(thisyear)
previousyearstart = yearstart(thisyear - 1)
nextyearstart = yearstart(thisyear + 1)
select case anydate
case is >= nextyearstart
isoweeknum = (anydate - nextyearstart) \ 7 + 1
yearnum = year(anydate) + 1
case is < thisyearstart
isoweeknum = (anydate - previousyearstart) \ 7 + 1
yearnum = year(anydate) - 1
case else
isoweeknum = (anydate - thisyearstart) \ 7 + 1
yearnum = year(anydate)
end select
if ismissing(whichformat) then
exit function
end if
if whichformat = 2 then
isoweeknum = cint(format(right(yearnum, 2), "00") & _
format(isoweeknum, "00"))
end if
end function
public function yearstart(whichyear as integer) as date
dim weekday as integer
dim newyear as date
newyear = dateserial(whichyear, 1, 1)
weekday = (newyear - 2) mod 7
if weekday < 4 then
yearstart = newyear - weekday
else
yearstart = newyear - weekday + 7
end if
end function
038.请教日期的转换问题
我的程序里有这样一段代码:
Dim str As Date
str=now
Sheet1.Cells(1, "A") = str
运行后在单元格里显示
2003/11/13 15:19:45
但我想让它显示成如下的格式:
2003年11月13日(小时,分,秒去掉)
我用year(str)想单独取得年的值,但显示1905/06/25 0:00:00
请问有什么好的方法可以实现这种转换吗?
解答:
Dim str As Date
str=now
Sheet1.Cells(1, "A") = format(str,"yyyy年mm月dd日")
039.如何用vba实现删除最右边的字符
1月、2月、3月...........10月、11月、12月
请问如何用vba实现把“月”删除只提取:1、2、3.......10、11、12。
解答:Sub abc()
Dim a As Integer
Dim b As String
Dim c As String
c = ""
For a = 1 To Len(b)
c = c & IIf(Mid(b, a, 1) <> "月", Mid(b, a, 1), "")
Next
MsgBox c
End Sub
或者:
A1= 1月、2月、3月、4月、5月、6月、7月、8月、9月、10月、11月、12月
[A1] = Application.WorksheetFunction.Substitute([A1], "月", "")
040.请问如何定义相对定位的名称
我想定义一个各个工作表(一个工作薄内)使用的名称。该名称为相对定位,
如我在sheet1表的B2中该名称是 sheet1 表的A2,我在sheet2表的B2中时该名称是sheet2表的A2单元格,可我在定义名称时它总是加上工作表名。