[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

trying to concatenate the last column variable into the range

Posted on 2015-01-31
4
Medium Priority
?
100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

650 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