Variable as reference in formula

rockblock

New Member
Joined
Mar 9, 2009
Messages
2
Hi,
<-- It's my first post on forum :p

I was reading about INDIRECT function but can't figure it out.
I have following code:
<CODE>
Sub try()
Dim x As Integer
For x = 1 To 1000
If Worksheets("Sheet1").Cells(x, 1).Value <> "" Then
Worksheets("Sheet1").Cells(x, 2).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'[Transport_WK7.xls]aaa'!C1:C12,2,0)"
Else: End If
Next x
End Sub
</CODE>


Workbook "TransportWK x " changes name every week and I want this code to get information about week number (bolded red) from workbook where macro is runned, let say from cell A1

Is it possible to use INDIRECT in this case, any other ideas?

Many Thanks,
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi,
<-- It's my first post on forum :p

I was reading about INDIRECT function but can't figure it out.
I have following code:
<CODE>
Sub try()
Dim x As Integer
For x = 1 To 1000
If Worksheets("Sheet1").Cells(x, 1).Value <> "" Then
Worksheets("Sheet1").Cells(x, 2).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'[Transport_WK7.xls]aaa'!C1:C12,2,0)"
Else: End If
Next x
End Sub
</CODE>


Workbook "TransportWK x " changes name every week and I want this code to get information about week number (bolded red) from workbook where macro is runned, let say from cell A1

Is it possible to use INDIRECT in this case, any other ideas?

Many Thanks,

Try this... It is completely untested.

Code:
Sub try()
Dim x, iWeek As Integer
For x = 1 To 1000
iWeek = Worksheets("Sheet1").Range("A1").Value
    If Worksheets("Sheet1").Cells(x, 1).Value <> "" Then
        Worksheets("Sheet1").Cells(x, 2).Select
        ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'[Transport_WK" & iWeek & _
            ".xls]aaa'!C1:C12,2,0)"
    Else: End If
Next x
End Sub
 
Last edited:
Upvote 0
HAHA:) - such simple and I've never thought about it :)

I think I will have to refresh my little knowledge of VBA :)

Thanks for fast reply!
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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