help! Error in loop

everettjsj2

New Member
Joined
May 19, 2011
Messages
4
Code:
[COLOR="RoyalBlue"]Sub Tabloop_Test3()
    Dim WS_Count As Integer
    Dim I As Integer
    Dim N As Integer
    Dim CellNum As String
    
    Application.ScreenUpdating = False
     
    WS_Count = ActiveWorkbook.Worksheets.Count
    
    
    For I = 3 To WS_Count
        Sheets("Overview").Cells(3, I - 1) = Sheets(I).Range("A1").Value 'Note that we subtract only 1 from I because we are not offsetting.
        
        Sheets(I).Range("B8").Copy Sheets("Overview").Cells(4, I - 1)
        Application.CutCopyMode = False
        
        Sheets("Overview").Cells(5, I - 1) = Sheets(I).Range("A5").Value
            
        Sheets("Overview").Cells(6, I - 1) = Sheets(I).Range("A6").Value
         
         For N = 1 To 242
            CellNum = Sheets("Overview").Cells(N + 8, 1).Value
            Sheets("Overview").Range("A8").Offset(N, I - 2).FormulaR1C1 = "=VLOOKUP(VLOOKUP(' & CellNum & ','RawNames'!R3C2:R365C3,2,FALSE),' & Sheets(I).Name & '!R9C2:R150C4,3,FALSE)"
         Next N
    Next I
    
    Application.ScreenUpdating = True

End Sub[/COLOR]
[\code]

I am getting a 1004 error on the line :[COLOR="SeaGreen"]Sheets("Overview").Range("A8").Offset(N, I - 2).FormulaR1C1 = "=VLOOKUP(VLOOKUP(' & CellNum & ','RawNames'!R3C2:R365C3,2,FALSE),' & Sheets(I).Name & '!R9C2:R150C4,3,FALSE)"[/COLOR]

any suggestions would be greatly appreciated!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try...

Code:
Sheets("Overview").Range("A8").Offset(N, I - 2).FormulaR1C1 = "=VLOOKUP(VLOOKUP(" & CellNum & ",'RawNames'!R3C2:R365C3,2,FALSE),'" & Sheets(I).Name & "'!R9C2:R150C4,3,FALSE)"
 
Upvote 0
thank you for the attempt but unfortunately I am still getting the same error. Very frustrating! thanks again for the try
 
Upvote 0
im getting error 1004 at this line:

Sheets("Overview").Range("A8").Offset(N, I - 2).FormulaR1C1 = "=VLOOKUP(VLOOKUP(' & CellNum & ','RawNames'!R3C2:R365C3,2,FALSE),' & Sheets(I).Name & !R9C2:R150C4,3,FALSE)"
 
Upvote 0
That's because you're mixing apostrophes (') with quotes ("). Have another look at the code I offered.
 
Upvote 0
After replacing that line of code with mine and running your code, no error occurred. So I don't know why you're getting that error. Hopefully some else will be able help.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top