LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Select only columns

Hello:

I'm using the following code to dynamically assign addresses based on
field headers for a report. They are address fields that are broken up
into 5 columns that I concatenate into 1 column. When I use
Intersect(ActiveSheet.UsedRange, Range("B:B, Z:Z")) it works fine, but
if I change to Intersect(ActiveSheet.UsedRange, Range(HAdd, BAdd)) it
treats it as Range(B:Z), how do I change this?

Here's the code!

Sub headername()
Dim MyCell As Range
Dim Rng As Range
Dim LRow As Integer
Dim HAdd As Range
Dim BAdd As Range

LRow = LastRow(ActiveSheet)
Set Rng = Range("A2:FF" & LRow)

'* Dynamically assigns addresses for HAdd and BAdd

'* Set HAdd
Set HAdd = Cells.Find(What:="HomeAddressLine1", _
After:=ActiveCell, LookIn:=xlFormulas, _
Lookat:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
HAdd = (HAdd.EntireColumn.Address)

'* Set BAdd
Set BAdd =
Cells.Find(What:="BusinessAddressLine1", _
After:=ActiveCell, LookIn:=xlFormulas, _
Lookat:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
BAdd = (BAdd.EntireColumn.Address)

'* Concatenates 5 address columns for Each HAdd and BAdd
For Each MyCell In Intersect(ActiveSheet.UsedRange,
Range(HAdd, BAdd))
MyCell.Formula = MyCell.Value & " " _
& MyCell.Offset(0, 1).Value & " " _
& MyCell.Offset(0, 2).Value & " " _
& MyCell.Offset(0, 3).Value & " " _
& MyCell.Offset(0, 4).Value
MyCell.Formula = LTrim(MyCell.Formula)
MyCell.Formula = RTrim(MyCell.Formula)
Next
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
error - select method failed - (columns.select) PBcorn Excel Programming 3 May 19th 08 10:49 AM
Macro won't select columns Vick Excel Discussion (Misc queries) 1 August 17th 07 02:17 AM
VB to go across and then select columns Darin Kramer Excel Programming 8 August 28th 06 11:06 PM
Select second columns only My View Excel Discussion (Misc queries) 3 July 7th 05 11:37 PM
Select from Columns ten Excel Programming 1 August 13th 03 05:56 PM


All times are GMT +1. The time now is 06:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"