[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

trying to concatenate the last column variable into the range

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

868 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