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

  • SEARCH
  • Home
  • 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 9052611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:13:03+00:00 2026-06-16T13:13:03+00:00

I’m new to VBA but I’m hooked! I’ve created a workbook that tracks overtime

  • 0

I’m new to VBA but I’m hooked! I’ve created a workbook that tracks overtime in 2 week blocks with one 2-week block per worksheet. The macro I’m trying to debug is designed to carry any changes made in a worksheet over to following worksheets. The trick is that the data in one row may be in a different row in following worksheets so I trying to use VLookup in a macro to keep it accurate.

Sub CarryForward()
    Dim Answer As String
    Answer = MsgBox("This should only be used for a PERMANENT crew change." & vbNewLine & "If you are adding a new person to the list," & vbNewLine & "please use the Re-Sort function." & vbNewLine & "Do you want to continue?", vbExclamation + vbYesNo, "Caution!")
    If Answer = vbNo Then
        Exit Sub
    End If
    Application.ScreenUpdating = False
    Dim ActiveWorksheet As String
    ActiveWorksheet = ActiveSheet.Name
        For i = (ActiveSheet.Index + 1) To Sheets("DATA").Index - 1
            For x = 5 To 25
                Dim a As String
                Dim b As String
                a = "B" & x
                b = "C" & x
                ActiveSheet.Range(b).Value = Application.WorksheetFunction.VLookup(a, Sheets(ActiveWorksheet).Range("B5:C25"), 2, False)
            Next x
            Range("A3").Select
        Next i
    Sheets(ActiveWorksheet).Select
    Application.CutCopyMode = False
    Range("A3").Select
    Application.ScreenUpdating = True
End Sub

I’m pretty sure it’s just a syntax error in the VLookup line of code. A lot of the help posted comes close to what I’m looking for, it just doesn’t get me over the finish line.

Any help would be appreciated!

  • 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-06-16T13:13:05+00:00Added an answer on June 16, 2026 at 1:13 pm

    It is a little unclear what you are trying to do, but reading between the lines I think

    • you want to lookup the value contained in cell named by a?
    • and put the result on sheet index i?

    Also, there is a lot of opportunity to improve your code: see imbedded comments below

    Sub CarryForward()
        Dim Answer As VbMsgBoxResult  ' <-- Correct Datatype
        Answer = MsgBox("This should only be used for a PERMANENT crew change." & vbNewLine & _
            "If you are adding a new person to the list," & vbNewLine & _
            "please use the Re-Sort function." & vbNewLine & _
            "Do you want to continue?", _
            vbExclamation + vbYesNo, "Caution!")
        If Answer = vbNo Then
            Exit Sub
        End If
        Application.ScreenUpdating = False
        ' Dim ActiveWorksheet As String  <-- Don't need this
        'ActiveWorksheet = ActiveSheet.Name <-- use object variables
        Dim wbActive As Workbook  ' <-- don't select, use variables for sheet objects
        Dim shActive As Worksheet
        Set wbActive = ActiveWorkbook
        Set shActive = ActiveSheet
        'Dim a As String ' <-- no point in putting these inside the loop in VBA.  And don't need these anyway
        'Dim b As String
        Dim SearchRange As Range
        Set SearchRange = shActive.Range("B5:C25") ' <-- Use variable to hold range
        Dim shDest As Worksheet
        Dim i As Long, x As Long '<-- dim all your variables
        For i = (shActive.Index + 1) To wbActive.Worksheets("DATA").Index - 1 ' <-- qualify references
            Set shDest = wbActive.Sheets(i)
            For x = 5 To 25
                'a = "B" & x <-- no need to create cell names
                'b = "C" & x
                ' I think you want to lookup the value contained in cell named by a?
                ' and put the result on sheet index i?
                '  Note: if value is not found, this will return N/A.  Add an error handler
                wbActive.Sheets(i).Cells(x, 3).Value = Application.VLookup(shActive.Cells(x, 2).Value, SearchRange, 2, False)
            Next x
            'Range("A3").Select
        Next i
        'Sheets(ActiveWorksheet).Select ,-- don't need these
        'Application.CutCopyMode = False
        'Range("A3").Select
        Application.ScreenUpdating = True
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

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.