?
Solved

trying to concatenate the last column variable into the range

Posted on 2015-01-31
4
Medium Priority
?
99 Views
Last Modified: 2015-01-31
Hi,
Keep getting an error on line 6. I cant seem to solve the concatenation
I'm trying to get the last column variable into the range.
'remove dashes from part numbers on DSV base data sheet
    'first get the last column
    LCDSV = WS3.Cells(1, Columns.Count).End(xlToLeft).Column
    
    'then remove dashes
    WS3.Range("A1:" & LCDSV & "1").Replace What:="-", Replacement:="", SearchOrder:=xlByColumns, MatchCase:=True

Open in new window

This is part of a much larger procedure that works fine, and even this part works OK if I hard code the column address into it, but the last column may change in the future.
Naturally, any help is most appreciated
0
Comment
Question by:Stephen Byrom
[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
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
Stephen Byrom earned 0 total points
ID: 40581198
Sorted it!
I realised after posting that the concatenation was trying to add the column number to the number one, which is silly!
I changed the last column lookup to get the address and not the column.
I have included the code in case any other newcomer to vba has the same problem
'remove dashes from part numbers on DSV base data sheet
    'first get the last column
    LCDSV = WS3.Cells(3, Columns.Count).End(xlToLeft).Address
    
    'then remove dashes
    WS3.Range("A3:" & LCDSV).Replace What:="-", Replacement:="", SearchOrder:=xlByColumns, MatchCase:=True

Open in new window

0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 40581199
Hi,

If I understand what you are trying to achieve from the small snippet of code you have provided, please replace the last line with this:

WS3.[A1].Resize(LCDSV).Replace What:="-", Replacement:="", SearchOrder:=xlByColumns, MatchCase:=True
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 40581201
:)

Just missed your discovering a solution on your own.

I did note, however, that you also changed the line:
LCDSV = WS3.Cells(1, Columns.Count).End(xlToLeft).Column
To:
 LCDSV = WS3.Cells(3, Columns.Count).End(xlToLeft).Address

Are you sure you wanted to include the first three rows in the eventual range, not just the first row (as per your original question)?
0
 
LVL 1

Author Comment

by:Stephen Byrom
ID: 40581216
Thanks for your comment, and yes I changed the range to accomodate the entire data from the supplier.
Thanks for your interest
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

762 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