Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6345573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:50:53+00:00 2026-05-24T20:50:53+00:00

I have a problem with my VBA code in an excel spreadsheet containing orders.

  • 0

I have a problem with my VBA code in an excel spreadsheet containing orders. Each row contains a customer number, which I use to look up the customer email address, contained in a different sheet in the workbook.

The vlookup code works fine for a single cell, but the problem is when I try to loop through all of the rows of the spreadsheet. The Excel formula for a single cell is, e.g.,

=VLOOKUP(B2,Customers!A2:D1000,4,FALSE)

The VBA code generated for this is:

    Range("M2").Select
ActiveCell.FormulaR1C1 = _
    "=VLOOKUP(RC[-11],Customers!RC[-12]:R[999]C[-9],4,FALSE)"

Incorporating this into a loop, after selecting the starting cell, I have the following:

Cells(2, 13).Select
Do
  ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-11],Customers!RC[-12]:R[999]C[-9],4,FALSE)"
  ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, -10))    

The problem is that I want the “table array” to be fixed, not relative to the cell whose value is being looked up. But I absolutely can’t figure out how to do it. If I change the code as follows, I get a run-time error:

ActiveCell.FormulaR1C1 = _
    "=VLOOKUP(RC[-11],Customers!A2:D1000,4,FALSE)"

I have tried quoting, unquoting, setting a range variable, using the range variable with .address… can someone please help?

Thank you so much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:50:55+00:00Added an answer on May 24, 2026 at 8:50 pm

    I’m pretty sure the brackets in your R1C1 formula indicate that you are specifying a relative range (especially with the negatives in them). If you want to specify an absolute range, you need to specify the R1C1 cells without brackets; e.g. R2C2:R4C4.

    As a simple example:

    Sub test()
      Sheet1.Range("C5").FormulaR1C1 = "=VLOOKUP(1,R1C1:R3C3,2,FALSE)"
    End Sub
    

    Running this gives you an absolute “A1”-style formula in cell C5.

    I think your problem might be:

    Customers!RC[-12]:R[999]C[-9]
    

    Because it is a relative range. You have to explicitly specify where your data table is; e.g. Customers!RC12:R999C9 (you need to figure out where it is on your sheet).

    An easy way of figuring this out is highlighting your data table on your worksheet, then switch to the Visual Basic Editor and manually run this (put your cursor inside of the Sub, and press the ‘Play’ button or go to Run->Run).

    Sub test2()
        Dim r As Range
        Set r = Application.Selection
        InputBox "your r1c1 range:", , r.Address(True, True, xlR1C1)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have VBA code in an Excel spreadsheet. It is used to set the
I have an excel spreadsheet which contains a calendar control (Microsoft Calendar Control 2007,
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
In VBA on Excel, I have a loop over several thousands of cells, which
I have a problem with some excel code that I am having trouble getting
I have an Excel VBA function that takes a number of optional parameters, including
I have a problem with calling the Match function from a VBA code: it
I have the following vba-code in an MS-Access97-frontend which opens a word-document stored on
I have an Excel file that has a bunch of VBA and macro code
I have a problem with a VBA Add-in in Excel 2010. I've created some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.