Dim m1 As Range, n As Long
Set the m1=Sheets (4). UsedRange
'n that represent the current forms the last line of the next line of data
N=m1. Row + m1. Rows. Count
Range (" A ", n)=teachernames. Value
Range (" B ", n)=textComboBox1. Value
Range (C, n)=textComboBox2. Value
Range (" D ", n)=modules. The Value
Range (" E ", n)=faculty. The Value
Range (" F ", n)=teacher_id. Value
'will form the input data to clear, wait for the next input
teachernames.Valuehttps://bbs.csdn.net/topics/=""
textComboBox1.Valuehttps://bbs.csdn.net/topics/=""
textComboBox2.Valuehttps://bbs.csdn.net/topics/=""
modules.Valuehttps://bbs.csdn.net/topics/=""
faculty.Valuehttps://bbs.csdn.net/topics/=""
teacher_id.Valuehttps://bbs.csdn.net/topics/=""
Unload Me
End Sub
It always shows "the range function and _global is wrong"
I put the range (" A ", n) into the range (" A ", CSTR (n)) not
Why is this excuse me?
CodePudding user response:
Writing has A problem, or written in cells (n, "A"), or written in range (" A "& amp; n)CodePudding user response:
Defining variables'Dim EXCEL process As New EXCEL. Application, EXCEL Workbook As New EXCEL. The Workbook, EXCEL worksheets As New EXCEL. The Worksheet
The Set of EXCEL process=CreateObject (" EXCEL. Application ") 'create EXCEL object
EXCEL process. DisplayAlerts=False 'block pop-up dialog
'open the workbook, (or new)
The Set of EXCEL workbook=EXCEL process. Workbooks. Open (" C: \ 123. XLS ") 'Open C: \ 123. XLS
Or the Set of EXCEL workbook=EXCEL process. Workbooks. The add (" C: \ 123. XLS ") 'to the C: \ 123. XLS as sample copy out a same table files (workbook)
Another is the Set of EXCEL workbook=EXCEL process. Workbooks. Add 'to create a new workbook
The Set of EXCEL worksheet=EXCEL workbook. Worksheets (1) 'Set the first table activity worksheet (current operating table)
Or the Set of EXCEL worksheet=EXCEL workbook. Worksheets (" sheet1 ") 'have Set the table name to sheet1 activity worksheet (current operating table)
A=EXCEL worksheets. Range take "(" A3") 'A3 cell values assigned to the variable a
EXCEL worksheets. Range (" A3 ")="123 ABC" '" A3 cell values into 123 ABC
Need special attention is that EXCEL worksheets. Range (" A3 ")="123 ABC" cannot be written as the Range (" A3 ")="123 ABC" because if it is written in the EXCEL process space cleared again after the prompt error (this is the Internet asked the most questions: why there is nothing wrong with EXCEL the first run, the second run error!!! Because the process after the memory space is freed, but reference space will not be released before the end of the program as a whole, this time if not forcibly appoint you to operate the prefix, namely must tell the program, which book do you want to access the cell, the program will access the default reference cell, that is to say, open the first time the cell of the file, so will be submitted to the remote server is not available (because the file has been closed) or entry cell errors (because of closed cell natural also doesn't exist))
Below is the cell operation
EXCEL worksheets. Range (" A3 ")="123 ABC" '" A3 cell values into 123 ABC
EXCEL worksheets. Cells (1, 2)="BBV" will be the first line of the second column value in the cell into a BBV
Below is the regional operation
EXCEL worksheets. Copy 'to replicate the entire worksheet
EXCEL Worksheets. Copy the EXCEL workbook. Worksheets (1) 'to create a Copy of the worksheet to EXCEL workbook under
EXCEL worksheets. Range (" A3 "). Copy 'copy the cell A3
EXCEL worksheets. Range (EXCEL worksheets. Cells (1, 2), EXCEL worksheets. Cells (5, 8)). This is the Copy Copy from line 1 column 2 to 5 rows 8 columns Range cell, is still the problem to note here is work table prefix must be specified, so if will EXCEL worksheets. Cells (1, 2) into Cells (1, 2) still can appear the second run error
Example:
EXCEL worksheets. Range (" A3 "). The copy (copy copy command)
EXCEL worksheets. Range (" A9 "). Paste are copied to A3 cell A9 (Paste Paste command)
EXCEL worksheets. Rows (1:3). Delete the Shift: 1 to 3=xlUp removed, fill mode Shift:=xlUp for below record up
EXCEL worksheets. The Columns (" off "). The Delete Shift:=xlToLeft Delete column 2 to 4 Shift:=xlToLeft as to the right column on the left side of the fill
EXCEL worksheets. Range (" A1: B3 "). The Merge 'cell A1 to B3 merger
EXCEL worksheets. UsedRange. Columns. The Count returned effective number of Columns, under the specific explanation with
EXCEL worksheets. UsedRange. Rows. Count the effective command will return a list of the current line number, that is to say we want to know how many Rows, the table was edited in the command returns an integer value that represents the table how many Rows were edited, pay attention to when using this command is "be edited" the word, because a few empty cell belongs to also be edited, although it has no data you also look not to come out but it's true there
EXCEL worksheets. Range (" A1 "). The Font Size=22 'set the A1 cell Font Size (these Settings can be obtained by recording VBA, not a list)
EXCEL workbook. Save 'to Save the worksheet
EXCEL worksheets. PageSetup. Cancel the Zoom Zoom=False '
EXCEL worksheets. PageSetup FitToPagesWide one page width=1 '
EXCEL worksheets. PageSetup FitToPagesTall=1 'one page, if you don't need a page is high=0
EXCEL object. ActiveWorkbook. PrintOut 'a print the entire workbook, and other functions, can baidu space is too big, can control the print
EXCEL workbook. Close False 'Close the current workbook, (False exit without saving this is corresponding to the above process of EXCEL. DisplayAlerts=False' block pop-up dialog this command, the pop-up dialog box has been blocked because it is over, this time is if the table and we didn't change the SAVE command to form words will ignore the changes and Close the table, in the Close position control False or True to inform whether to SAVE before exit)
EXCEL process. The Quit close EXCEL process
Set=Nothing 'EXCEL worksheets to release the variable "EXCEL worksheets" resources, system memory back (there's a myth that the first run the second anomaly, a lot of friends all say this a few commands without cause, actually has little to do, this command is only our definition of the variable occupied memory space back to space, as if to define a variable is used up when no release variable content)
The Set of EXCEL workbook=Nothing 'release the variable "EXCEL workbook" resources
The Set of EXCEL process=Nothing 'release the variable "EXCEL process" resources
CodePudding user response: