How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Richard Your Own Question

Richard
Richard, Software Specialist
Category: Microsoft Office
Satisfied Customers: 16842
Experience:  Over 15 year experience resolving Microsoft Office Issues
32989067
Type Your Microsoft Office Question Here...
Richard is online now
A new question is answered every 9 seconds

I am writing a macro which includes accessing data in stored

Resolved Question:

I am writing a macro which includes accessing data in stored documents. To access an individual cell, I use the contents of cell AM3 as the modifier:

myrow = Range("AM3")
Range = ("A" & myrow).Select

I now have to access a range of data, modified by cell AM3 and tried the following:
myrow = Range("AM3")
Range = ("A" & myrow : "C" & myrow + 8)

What is the correct coding ?
Submitted: 1 year ago.
Category: Microsoft Office
Expert:  Richard replied 1 year ago.
Thank you for your question, my name is Richard.

To clarify, say the range has 3 5 6 in three cells

you want the variable to have stored 356 so all three values?

Thank you

Customer: replied 1 year ago.

Hi Richard,


I have a name and address stored in cells A115 to C123 , the next address in cells A165 to C173, the next in cells A215 to C223 etc. Cell AM3 contains the cell number of the start of the range, eg 115 or 165 or 215 etc


 


Does that help ?


 


My name is Robin

Expert:  Richard replied 1 year ago.
Nearly Robin
So basically you want to reference the cell that is specified in AM3

so AM3 has A165

And you want code that says get the value of the cell specified in AM3?

If you explain the overall achievement you want in your own words, that can help.

Thank you

Customer: replied 1 year ago.

Not quite. Not a single cell, but a range of cells, which could be from A115 to C123, or A165 to C173, or A215 to C223 etc. The value in cell AM3 will be 115 or 165 or 215 etc , which will give the start cell number of the range.

Expert:  Richard replied 1 year ago.
Can I look at this spreadsheet?

It is easier

- Click the following link: http://www.wikisend.com
- Upload the file to that website
- Once it is uploaded, the resulting page will display a "File ID" number.
- Please, give me that "File ID Number"

Thank you
Customer: replied 1 year ago.

The spreadsheet is over 10mg and is difficult to email. This question is intended for a Visual basic expert.

Expert:  Richard replied 1 year ago.
I am a Visual Basic Expert, and I dont want you to email the file.

I want you to upload it please.

- Click the following link: http://www.wikisend.com
- Upload the file to that website
- Once it is uploaded, the resulting page will display a "File ID" number.
- Please, give me that "File ID Number"

Customer: replied 1 year ago.


Sorry, but I cannot spend any more time on this. I have an urgent appointment and will have to find someone else who can give me a quick answer.


Thanks for trying to help me

Expert:  Richard replied 1 year ago.
sure
Expert:  Richard replied 1 year ago.
I'll take an educated guess, though I am still not clear on your code.

But you can use

Dim SrcRange As Range

Set SrcRange = Sheets("Src").Range("A" & Range("AM3") & " : " & Range("AM3")+8)

This puts the range, based on the value of AM3 into a Range variable.
Customer: replied 1 year ago.

Thanks Richard.


Just so there is no confusion, the following would be my coding if I were copying a fixed cell to a destination cell.


 


Sheets("DATA").Select


Range("A115").Select


Selection.Copy


Sheets("CUST").Select


Range("A1").Select


ActiveSheet.Paste


 


If the source cell could be one of 100 different cells, the cell AM3 will be set to the value of the appropriate one to action. Thus the code would now be :


 


Sheets("DATA").Select


myrow = Range("AM3")


Range("A" & myrow).Select


Selection.Copy


Sheets("CUST").Select


Range("A1").Select


ActiveSheet.Paste


 


So, whatever value is assigned to cell AM3, that cell in column A will be selected.


 


Now I wish to go one step further. Instead of selecting a single cell, I have to select a range of cells.


 


If their location was fixed, the code would be


 


Sheets("DATA").Select


Range("A115..C120).Select


Selection.Copy


Sheets("CUST").Select


Range(A1").Select


ActiveSheet.Paste


 


However, because the source range may be one of 100, I was hoping that there was some code to use the contents of cell AM3 to specify the specific range that I required.


 


If that all makes sense could you let me have the code.


 


Many thanks in anticipation


 

Expert:  Richard replied 1 year ago.
ok, you would use the code as this

myRow = Range("AM3")

Sheets("DATA").Select

Range("A" & myRow & " : C120").Select

Selection.Copy

Sheets("CUST").Select

Range(A1").Select

ActiveSheet.Paste


This is the code you would use for this which would select the range based on the value of AM3

Let me know if you have any difficulties please

Thank you
Customer: replied 1 year ago.

Great. Many thanks Richard.


One more thing. Could the source sheet, DATA, be variable as well?


 


In other words, is there code to access the sheet using a variable, such as AM3 is used for the cell, to set the Sheet which must be accessed ?

Expert:  Richard replied 1 year ago.
Yes, no problem at all

In my example I say that AM2 has the sheet name. You just use any cell you wish.

The code is as follows.

myRow = Range("AM3")
mySheet = Range("AM2")

Sheets(mySheet).Select

Range("A" & myRow & " : C120").Select

Selection.Copy

Sheets("CUST").Select

Range(A1").Select

ActiveSheet.Paste

If you have any problems, or would like any additional information or assistance, please do not hesitate to let me know.

And if you can take a second to rate my service, that would be greatly appreciated.

Thank you
Richard, Software Specialist
Category: Microsoft Office
Satisfied Customers: 16842
Experience: Over 15 year experience resolving Microsoft Office Issues
Richard and 2 other Microsoft Office Specialists are ready to help you
Customer: replied 1 year ago.

Thanks so much Richard. I have done the rating.


One final point. In your answer you use cell C120. I would like to use C and myrow + 25.


In other words, If AM3 contains 115 the range extends from A115 to C140.


 


Could you rewrite just that one line of code ?


 


Many thanks, Robin

Expert:  Richard replied 1 year ago.
Of course

myRow = Range("AM3")
mySheet = Range("AM2")

Sheets(mySheet).Select

Range("A" & myRow & " : C" & myRow + 25).Select

Selection.Copy

Sheets("CUST").Select

Range("A1").Select

ActiveSheet.Paste

Let me know if you have any difficulties please

Thank you
Customer: replied 1 year ago.

Sorry Richard, but I am getting an Error 1004 , Method 'Range' of object'_Global' failed

Expert:  Richard replied 1 year ago.
This means the value you are using is not valid in your code.

On which line do you get the error?

this is why I wanted the file as there are many variables that can cause this.

Customer: replied 1 year ago.

Sorry. It is line number 4. Maybe I have got a space where I shouldn't have one.


 


My exact code is as follows :


 


Sheets("DATA").Select


mySheet - Range("AM3")


Sheets(mySheet).Select


myRow = Range("AC9")


Range("A" & myRow & " : H" & myRow + 25).Select


Selection.Copy


 


 

Expert:  Richard replied 1 year ago.
Yes, but it also invovles data on the sheet.

This is why I initially wanted to see the sheet

- Click the following link: http://www.wikisend.com
- Upload the file to that website
- Once it is uploaded, the resulting page will display a "File ID" number.
- Please, give me that "File ID Number"
Customer: replied 1 year ago.

File ID No is 440880. The file should open at the point where you can activate the macro using Control and f.

Expert:  Richard replied 1 year ago.
This is the problem

myrow = Range("AC9")
Range("A" & myrow & " : H" & myrow + 50).Select

But Cell AC9 on Dat is empty

This is the reason for the error.

Customer: replied 1 year ago.

O.K. but the line before myrow = Range("AC9") should specify Sheet 1 and cell AC9 of sheet 1 contains 114.

Expert:  Richard replied 1 year ago.
There is no Sheet 1 in your book

Customer: replied 1 year ago.

When you open the uploaded version, you are in sheet 1. It is called 1 not sheet 1.

Expert:  Richard replied 1 year ago.
ok, the problem is you dont define the variable.

You need to do this with all variables

At the top, before the code starts, (under the Sub name)

Put

Dim mySheet As String

It needs to be a String Data Type

Let me know if you have any difficulties please
Customer: replied 1 year ago.

Great !! It now works fine.


 


Many thanks for all the time that you have spent Richard

Expert:  Richard replied 1 year ago.
Anytime

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
< Last | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
 
 
 

Meet The Experts:

 
 
 
  • jstinehelfer

    Information Systems Manager

    Satisfied Customers:

    36
    A+ Comptia Certified computer repair
< Last | Next >
  • http://ww2.justanswer.com/uploads/JS/jstinehelfer/2012-6-6_215146_Pictureofme1.64x64.png jstinehelfer's Avatar

    jstinehelfer

    Information Systems Manager

    Satisfied Customers:

    36
    A+ Comptia Certified computer repair
  • http://ww2.justanswer.com/uploads/JA/JasonJames122/2011-12-16_135647_jasonjamesheadshotweb.64x64.jpg JasonJames122's Avatar

    JasonJames122

    Computer Enthusiast

    Satisfied Customers:

    0
    I manage all information systems (network of Windows PC's and servers with Microsoft Office products) for a small business
  • http://ww2.justanswer.com/uploads/JE/jessmagz/2012-6-6_18129_jm.64x64.jpg Jess M.'s Avatar

    Jess M.

    Computer Support Specialist

    Satisfied Customers:

    301
    Computer Software Specialist for more than 10 years
  • http://ww2.justanswer.com/uploads/CH/chutz747/2011-11-6_14231_me.64x64.jpg The-PC-Guy's Avatar

    The-PC-Guy

    Computer Manager

    Satisfied Customers:

    274
    20 years experience providing remote computer support
  • http://ww2.justanswer.com/uploads/SP/spherrod/2012-6-6_174244_1000852.64x64.JPG Steve Herrod's Avatar

    Steve Herrod

    Computer Support Specialist

    Satisfied Customers:

    125
    Trained in Microsoft Office from 2000 through to latest version 2010.
  • http://ww2.justanswer.com/uploads/SE/Seashore2011/2011-12-6_33418_111205223015.64x64.jpg Chris L.'s Avatar

    Chris L.

    Support Specialist

    Satisfied Customers:

    124
    Certified Expert with over 10 years experience.
  • http://ww2.justanswer.com/uploads/KR/krkljatorm/2012-6-24_153417_ITMiro.64x64.jpg IT Miro's Avatar

    IT Miro

    Computer Scientist

    Satisfied Customers:

    97
    Bachelor's Degree in Information Technology, Microsoft Certified Professional
 
 
 

Related Microsoft Office Questions

Chat Now With A Microsoft Office Technician
Richard
Richard
IT Manager
902 Satisfied Customers
Over 15 year experience resolving Microsoft Office Issues