Solved

Problem to the line

Posted on 2015-02-09
4
87 Views
Last Modified: 2015-02-09
Hi,
The original Excel file is version 2003, after I've re-saved it as Excel 2010 macro-enabled version, and then tried to run the macro, I get the attached problem, due to this line

        Range(objShtDst.Cells(intcurdstrow, 2), objShtDst.Cells(intcurdstrow, 6)).Select

Open in new window


why?
t968.png
0
Comment
Question by:HuaMinChen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40597852
in a macro, you rarely need to actually "select" the range, but rather use the range object.
meaning that instead of doing:
range.Select
selection.dosomething

you do
range.dosomething
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40597862
Thanks. It has codes like

        Range(objShtDst.Cells(intcurdstrow, 2), objShtDst.Cells(intcurdstrow, 6)).Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
...

Open in new window


how to correct the problem to 1st line in above?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 40597885
this should not only work without the error, but will also run faster:
dim r as Range
set r =  Range(objShtDst.Cells(intcurdstrow, 2), objShtDst.Cells(intcurdstrow, 6))
        r.Borders(xlDiagonalDown).LineStyle = xlNone
        r.Borders(xlDiagonalUp).LineStyle = xlNone
        r.Borders(xlEdgeLeft).LineStyle = xlNone
        r.Borders(xlEdgeTop).LineStyle = xlNone

Open in new window

0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 100 total points
ID: 40597902
It's also better to qualify the Range call:

set r =  objShtDst.Range(objShtDst.Cells(intcurdstrow, 2), objShtDst.Cells(intcurdstrow, 6))

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question