?
Solved

Problem to the line

Posted on 2015-02-09
4
Medium Priority
?
90 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 11

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 1200 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 300 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

801 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