Excel VBA three essays

Changes in the workbook saved, it is automatically backed up
do not use the Save As, thisWorkbook.SaveAs "d: \ data \ 1.xlsx"
so when Save finished, it will automatically open the saved file 1.xlsx, the current file will be changed 1.xlsx is
to ensure that all operations are in the original file, can not affect the user's operation

There is secretly saved events:
edit the workbook file: Workbook - beforeSave
thisWorkbook.savecopyas "d: \ data \ 1.xlsx"
When you click save time, would secretly keep a backup file
"d: \ data \ 1.xlsx "changed to" d:. \ data \ " & format (now ()," yyyymmddhhmmss ") &" xlsx "

If you can not remember, to record a macro, copy the code, you can modify the code

The set of all functions worksheet:
application.WorksheetFunction.CountA (sheet2.range ( "a: a")) Table II a number of non-null columns

WorksheetFunction.CountIf(sheet2.range("f:f"), "男")

WorksheetFunction.VLookup(sheet1.range("d9"), sheet2.range("a:b"), 5, 0)

VBA error occurs, continue:
Error avoidance:
ON error Resume the Next

For text: text digital to digital: val (l)
Text-to-digital: L = L *. 1 (multiplied. 1)
IF vba.Information.IsNumeric (L) = False or L <0 the then
IF the IsNumeric (L) = false or l <0 then

dim i as string

The resulting array is divided: Split (the Range ( "a2"), "-") (0)

自定义公式:
function zmj(str as String, str1 as string, i as Integer)
    if str = "男" then...
end function

function jqzf(str as String, str1 as string, i as Integer)
    jqzf == split(str,str1)(i-1)
end function


sub cjb(str as string)
...
end sub

sub test()
call cjb(sheet1.range("a1"))
end sub

VBA is loaded into the main program will excel in
the Save as default add-xla or xlam
file option, the Quick Access Toolbar for all documents

Create a table into the variable
Dim SHT AS Worksheet
the SET SHT = Sheets.Add
sht.name = "February"

dir:
if the file and return a file name (including the extension), does not return empty, (note suffix XLS, XLSX)
Range ( "A1") the dir = ( "D: \ Data \ heheda.xls *")

Suzhou and Suzhou .xls .xlsx
Range ( "A1") the dir = ( "D: \ Data \ Suzhou .xls *") a Suzhou .xls
Range ( "A2") returns the dir = Suzhou .xlsx
Range ( "A2" ) = dir returns a null
range ( "a2") = dir error

All files: dir ( "d:. \ The Data \ * XLS *")

Open the file: Workbooks.Open ( "file address")
Dim wb AS wrokbook
the SET wb = Workbooks.Open ( "file address")
. . .
wb.close

Merge multiple files

dim wb as wrokbook
set wb = workbooks.open("文件地址")
wb.sheets(1).copy after:=thisWorkbook.sheets(thisWorkbook.sheets.count)
thisWorkbook.sheets(thisWorkbook.sheets.count).name = split(wb.name,".")(0)
wb.close

Find a formula, will not find the error, the error will not use the set
range. ( "D: d" ) find ( " Joe Smith") .Select
'the Range. ( "D: d") the Find (the Range ( "L3") ) .offset (0,3)
SET RNG = Range (. "D: D") Find (Range ( "L3"))
IF RNG IS Nothing the then
MsgBox "not found"

dim sht as worksheet
set sht = activesheet


 

Released nine original articles · won praise 1 · views 2242

Guess you like

Origin blog.csdn.net/qq_38240938/article/details/104504798
Recommended