dwhitey1124
New Member
- Joined
- Oct 24, 2014
- Messages
- 28
Hi all,
I have two sheets in my file. The first sheet (sheet1) is a control tab with a list of names and values. The second sheet (sheet2) is a more comprehensive list of names and values. On the control tab, I have a table of names and values to override pre-populated values on the second sheet. I have tried to write a macro that cycles through J5:J45 of the control tab. If the the cell is blank, it goes on to the next row. If it is not blank, the macro finds the row of the value in (i, J) in sheet2 A1:A400. It then finds the column of value (i, G) in A3:AA3 of sheet2. Using this match/match process, it then enters the value in that cell as (i, K) from sheet1. When I run the macro, I am getting a "Next without For" error. I hope it is an easy fix.
If anyone can think of how to address the issue or has an idea for a better macro, I would love to hear it. Thank you in advance.
I have two sheets in my file. The first sheet (sheet1) is a control tab with a list of names and values. The second sheet (sheet2) is a more comprehensive list of names and values. On the control tab, I have a table of names and values to override pre-populated values on the second sheet. I have tried to write a macro that cycles through J5:J45 of the control tab. If the the cell is blank, it goes on to the next row. If it is not blank, the macro finds the row of the value in (i, J) in sheet2 A1:A400. It then finds the column of value (i, G) in A3:AA3 of sheet2. Using this match/match process, it then enters the value in that cell as (i, K) from sheet1. When I run the macro, I am getting a "Next without For" error. I hope it is an easy fix.
If anyone can think of how to address the issue or has an idea for a better macro, I would love to hear it. Thank you in advance.
VBA Code:
sub OverRide()
Sheet1.Select
For i = 5 To 45
Cells(i, 10).Select
If Cells(i, 10).Value <> "" Then
Sheet2.Select
Dim lRow1 As Long
Dim lColumn1 As Long
On Error Resume Next
lRow1 = Application.WorksheetFunction.Match(Sheet1.Cells(i, 10).Value, Range("A1:A400"), 0)
On Error Resume Next
lColumn1 = Application.WorksheetFunction.Match(Sheet1.Cells(i, 7).Value, Range("A3:AA3"), 0)
On Error GoTo 0
If lRow1 > 0 Then
'code
Cells(lRow1, 1).Offset(0, lColumn1 - 1).Select
ActiveCell.Value = Sheet1.Cells(i, 11).Value
End If
Next i
End Sub