Solved

Problem to the line

Posted on 2015-02-09
4
74 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
  • 2
4 Comments
 
LVL 142

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 142

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now