Thursday 15 September 2011

excel - Copying cell values from one Workbook into another -


I have the following code that I've written for taking a few names and used them to populate tilesheets.

  sub initNames () Dim I as integer I = 0 as the dim name string Windows ("employee data .xlsx"). Active sheet ("employee"). Choose Range ("A2"). IsEmpty (ActiveCell) name = ActiveCell.Value workbooks ("Timesheets"). Sheet ("ST"). Range ("A9") Offset (i * 9) .Volume = Name ActiveCell.Offset (1, 0). Select loop and sub  

Basically, the cells present in the target sheet remove 9 rows from each other, hence the first name is in cell A9, second in A18, in A7 Third, and so on. I'm sure I have some incredibly simple, but I have not received any response from Excel (no error message). The cells in the Timesheet are merged cells, but I can not change them (locked by the owner), but I do not think there is anything to do with it.

Edit : I've added a line: basicvalue = workbooks ("Timesheets") Sheets ("ST"). Range ("A10") Offset ((x - 2) * 9, 0). So I could see what values ​​were being overwritten in my timesheets and I have seen some interesting things: the original cell should only be before the text of the cell (A9) After that, each cell captures (A18, A27, etc.). ) Debugger indicates that OriginalValue = "" Although there are names in these cells, however, when I open another worksheet and reference A9, A18, etc., I am taking the name.

Edit 2 : I modified the test line to read the workbook ("Timesheets"). Sheets ("ST"). Range ("A" & ((X - 1 * 9)). Value = "test" which does change the values ​​in all target cells. Why VBA allow me to allocate "test" to a cell value, but why not name it in other worksheet?

"post-text" itemprop = "text">

Try something like this, it will complete the task that you are requesting without using . Choose or . Activate

  Sub InitNames () Dim I as Integer Dim Wksht as Worksheet i = 0 Set Wksht = Workbooks ("employee data.clicks"). Wksht.Range ("A" and "Wksht.Rows.Count") for Sheet ("Employee") I = 2. End (xlUp) .row workbook ("Timesheets") Sheets ("ST"). Range ("A9") Offset ((i-2) * 9.0) Value = Wacchat Category ("A" and "I"). Value next i sub subdomain  
ends

No comments:

Post a Comment