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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:58:09+00:00 2026-06-17T07:58:09+00:00

With the code below I get an error: Run-time error ‘1004’ Method ‘Range’ of

  • 0

With the code below I get an error:

Run-time error '1004' Method 'Range' of object'_Worksheet failed.

   Dim destLastCol As Integer 'last column in range
   Dim destLastRow As Integer  'last row in range 
   Dim wsCrewDetail As Worksheet '

   Set wsCrewDetail = Worksheets("CrewDetail_M")
   destLastCol =  integer assigned previously
   destLastRow =  integer assigned previously

   With wsCrewDetail.Range(Cells(4, 1), Cells(destLastRow, destLastCol)) <== error here
    .Sort Key1:=.Cells(4, 2), Order1:=xlAscending, _
     key2:=.Cells(4, 1), Order2:=xlAscending, _
     key3:=.Cells(4, 3), order3:=xlAscending, Header:=xlYes
   End With

I’ve searched and viewed many examples trying many variations on setting the Range reference and nothing is working.

What is correct reference syntax please?

Edited to add destLastRow = integer assigned previously and edit to show destLastCol

  • 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-17T07:58:10+00:00Added an answer on June 17, 2026 at 7:58 am

    Well you aren’t feeding a row number into destLastRow in this line
    With wsCrewDetail.Range(Cells(4, 1), Cells(destLastRow, destLastCol))

    Plus, don’t use Integer variables, use Long. They are more efficient and also cater for large numbers.

    suggestions

    • using shorter variables such as ws for Worksheet makes it easier to type and read code
    • use Long rather than Integer
    • I would normally set a working range (rng1) rather than use a longer object starting with the sheet
    • dummy destLastRow and destLastCol values

    sample code

       Dim destLastCol As Long 'last column in range
       Dim destLastRow As Long  'last row in range
       Dim ws As Worksheet
       Dim rng1 As Range
    
       Set ws = Worksheets("CrewDetail_M")
       destLastCol = 6
       destLastRow = 10
    
       Set rng1 = ws.Range(ws.Cells(4, 1), ws.Cells(destLastRow, destLastCol))
       With rng1
        .Sort Key1:=.Cells(4, 2), Order1:=xlAscending, _
         key2:=.Cells(4, 1), Order2:=xlAscending, _
         key3:=.Cells(4, 3), order3:=xlAscending, Header:=xlYes
       End With
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error when I run the code below. I have normally used
I get the SIGSEGV - Segmentation Fault on the run-time for the code below
I get this error, while I'm testing the code below: You have an error
I get the following error with the code below. expected constructor, destructor, or type
I get the following error when running the code below: invalid byte sequence in
In the below code: var id=obj.setid({{info}}); I get an error saying illegal character and
I get the following error when I try and execute the code down below.
We get expected : end of statement error for the below code and VB
I get an error in the bellow code it says I cannot convert method
Trying to get radiobuttons binding working but getting a run time error with the

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.