I need some help with this code below.
I am trying to write a program which will scan a column in sheet 2 and have a conditional statement where if an "x" character is encountered then the data adjacent to that cell in the same row will be copied and pasted into a different sheet.
The program I have currently successfully copies A1 into Sheet 1 but not the other ones, I'm assuming there is some kind of incrementation error, but I can't detect it.
Any help is appreciated.
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
Update the code of the For
loop in your code to read
For n = 0 To (Process_Control_NumRows - 1)
This will increment n as you want it to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.