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: 36
Default Combining VBA code for columns

Hi-

I have the following code that I run for 8 consecutive
columns....columns I through P. As of now I am repeating this code 8
times (8 seperate blocks of code). This is obviously slowing the
process down quite a bit. My question is this: Is there a way to
combine all 8 columns into one block of code? Here is the code I am
using:

Range("I8").Select
Set rng = Range(ActiveCell.Address)
ActiveCell.Offset(1, -7).Range("A1").Select

Do Until ActiveCell.Value = ""
ActiveCell.Offset(0, 7).Range("A1").Select
If ActiveCell.Value < "" Then
l = ActiveCell.Value + l
ActiveCell.Offset(1, -7).Select
Else
rng.Activate
ActiveCell.Value = l
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Set rng = Range(ActiveCell.Address)
ActiveCell.Offset(1, -7).Select
l = 0

End If
Loop

rng.Activate
ActiveCell.Value = l
l = 0

Then I have this code for column J....

Range("J8").Select
Set rng = Range(ActiveCell.Address)
ActiveCell.Offset(1, -8).Range("A1").Select

Do Until ActiveCell.Value = ""
ActiveCell.Offset(0, 8).Range("A1").Select
If ActiveCell.Value < "" Then
l = ActiveCell.Value + l
ActiveCell.Offset(1, -8).Select
Else
rng.Activate
ActiveCell.Value = l
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Set rng = Range(ActiveCell.Address)
ActiveCell.Offset(1, -8).Select
l = 0

End If
Loop

rng.Activate
ActiveCell.Value = l
l = 0

TIA,
Chris

 
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
combining two columns together tadwestie Excel Discussion (Misc queries) 2 January 7th 10 10:21 AM
combining columns jason2444 Excel Discussion (Misc queries) 4 February 6th 09 06:47 PM
Combining Text from 2 Columns into 1 then Deleting the 2 Columns sleepindogg Excel Worksheet Functions 5 September 19th 08 12:36 AM
combining columns all the way down sparkroms Excel Discussion (Misc queries) 3 July 8th 05 08:28 PM
combining 2+ wkbks into 1. Code needs tweaking please ian123[_31_] Excel Programming 12 January 3rd 04 11:20 PM


All times are GMT +1. The time now is 11:30 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"