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 7594003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:18:39+00:00 2026-05-30T21:18:39+00:00

was wondering if anyone could help me solve the following problem. I’m given a

  • 0

was wondering if anyone could help me solve the following problem.
I’m given a runtime error 1004, over at With Worksheets("Sheet1").Cells(Rowtosave, EGCheck) Have spent quite some time trying out but still unable to define the error myself. Should anyone nice, care to help me out? Will appreciate your help. Thanks!

Sub Macro1()

Dim LastRow1 As Long, RowCheck As Long, Rowtosave As Long, LastCol1 As Long
Dim EGCheck As Long, ColEG As Range, firstEG As Long


LastRow1 = 50
LastCol1 = 50

   For RowCheck = 1 To LastRow1
'Look for "Name"
     With Worksheets("Sheet1").Cells(RowCheck, 1)
         If .Value = "Name" Then
     'Set row to Rowtosave for later use
           Rowtosave = RowCheck

         End If
    End With

 Next RowCheck

     For EGCheck = 1 To LastCol1
      'Look for EG on the name row with varying column
      'Since already obtain the row for name as Rowtosave, so set Row to Rowtosave
        With Worksheets("Sheet1").Cells(Rowtosave, EGCheck)
          If .Value = "EG" Then

           firstEG = EGCheck

         End If
       End With

Next EGCheck
  • 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-30T21:18:39+00:00Added an answer on May 30, 2026 at 9:18 pm

    There’s something wrong with your situation that isn’t shown here. When I enter the following:

    Option Explicit
    
    Sub Macro1()
        Dim LastRow1 As Long, RowCheck As Long, Rowtosave As Long
        Dim LastCol1 As Long, EGCheck As Long
    
        Range("a1:a1").Value = -1
    
        LastRow1 = 50
        LastCol1 = 50
    
        For RowCheck = 1 To LastRow1
            With Worksheets("Sheet1").Cells(RowCheck, 1)
                If .Value = "Name" Then
                    Rowtosave = RowCheck
                End If
            End With
        Next RowCheck
    
        For EGCheck = 1 To LastCol1
            With Worksheets("Sheet1").Cells(Rowtosave, EGCheck)
                If .Value = "EG" Then
                    Range("a1:a1").Value = Rowtosave * 10 + EGCheck
                End If
            End With
        Next EGCheck
    End Sub
    

    and put Name and EG into cells A6 and D6 respectively, I end up with a 64 in cell A1, as expected. In other words, it’s working fine.

    However, if I remove Name from cell A6, I get the error 1004, same as you. That’s because, in that case, Rowtocheck is never being set, hence it will have it’s default value of zero.

    And, when you attempt to use 0 as the rown in the Cells() call, it errors because the row must be one or more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if anyone could help me with this problem i'm having. I
Hi guys I was wondering if anyone could help me with the following: I
I was wondering if anyone could help me with the following issue. On our
I was wondering if anyone could help me solve how to view $_POST requests.
I was wondering if anyone could help me with this problem: I have to
I am stuck on this problem and was wondering if anyone could help me
Wondering if anyone could help me? I've recently switched over to Mac and trying
I was wondering if anyone could help me with this minor problem. I want
I was wondering if anyone could help me with the following. I work remotely
Hey there, was wondering if anyone could help a newbie on SQL and Python.

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.