Solved

trying to concatenate the last column variable into the range

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

Independent Software Vendors: 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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

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