Solved

trying to concatenate the last column variable into the range

Posted on 2015-01-31
4
88 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
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 Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

746 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

15 Experts available now in Live!

Get 1:1 Help Now