[英]Excel VBA: scanning one sheet and copying data to another
我需要以下代碼的幫助。
我正在嘗試編寫一個程序,該程序將掃描工作表2中的一列並有一個條件語句,其中如果遇到“ x”字符,則將復制同一行中與該單元格相鄰的數據並將其粘貼到另一張工作表中。
我目前已成功將A1復制到工作表1中的程序,但沒有成功將其復制到工作表1中,我假設存在某種增量錯誤,但我無法檢測到它。
任何幫助表示贊賞。
Sub autofill_DSR()
' Variable Declarations:
' We want variables which keep a count of the total number of rows,
' the item code character values associated, a count of the total
' number of "x" characters encountered, and a flag to signify
' sheet transfer activation
Dim sheet_flip_flag, x_count, n As Integer
Dim item_a, item_b As String
Process_Control_NumRows = 16
Sheets(Array("Sheet1", "Sheet2")).Select
Sheets("Sheet2").Activate
Range("D1").Select
For n = 0 To n = (Process_Control_NumRows - 1)
If (ActiveCell.Offset(n, 0) = "x" Or ActiveCell.Offset(n, 0) = "X") Then
item_a = ActiveCell.Offset(n, -3).Value
item_b = ActiveCell.Offset(n, -2).Value
Sheets("Sheet1").Activate
Range("A1").Select
ActiveCell.Offset(n, 0).Value = (item_a & item_b)
Sheets("Sheet2").Activate
Range("D1").Select
End If
ActiveCell.Offset(n, 1).Value = NN
Next n
End Sub
更新代碼中的For
循環代碼以進行讀取
For n = 0 To (Process_Control_NumRows - 1)
這將根據需要增加n。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.