Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Looping through rows and shifting certain contents

I'm pretty new to VBA, but love the few things I have been able to do
so far . . . here's what I want to do now:

I have a semi-colon delimited download from a program. I put it
through the text-import wizzard and it imports to columns almost
perfectly . . . Almost. Out of the 10,000 or so lines on the import, a
handful were not delimited properly on the data dump. This is
resulting in some of the data being shifted left either one or two
columns. (see example below of the last three columns of my data dump)

My pre-VBA solution was to filter the column AK by BLANK and then
manually shift the data to the right one or two rows (whatever it
needed). Now that I'm falling in love with VBA, i understand the time
that automating this process could save.

Here's what I'm trying to do in plain English

For each row I want to

If the contents of AJ are = 0 than do nothing,
If the contents of AJ are blank "", then I want to shift the contents
of Column T through AI two cells to the right

Then I will do a similar loop through Column AK, with the only
difference being
If the contents of AI are blank "", then I want to shift the contents
of Column U through AJ ONE cell to the right

Here's what I've tried for the Column AJ loop:

Sub MoveBadRows()
'This Sub is not good yet
Range("aj2").Select

Do While Selection.Offset(0, -1) < ""
If IsEmpty(ActiveCell) Then
Range(ActiveCell.Offset(0, -1):ActiveCell.Offset(0,
-16)).Select
Selection.Cut Destination:=ActiveCell.Offset(0,
2).Range("A1:P1")
ActiveCell.Offset(1, 0).Select

Else: ActiveCell.Offset(1, 0).Select
End If
Loop


End Sub

I know that my problems are :
1) In defining the range that is to be moved
2) Getting the active cell back a single cell in column AK

AI AJ AK
0 0 0
0
0 0 0
0 0
0 0 0
0
0 0 0
0 0
0 0 0




Note:My download always has 37 columns (AK) and varying number of rows.

Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Looping through rows and shifting certain contents

OK, I dug in a little more and came up with this solution. It's not a
super fast calculation, but it works faster than I could manually. I
may add something to it to only do the calcs on filtered rows or
something.

Sub MoveBadRows()

Range("aj2").Select

Do While Selection.Offset(0, -1) < ""

If IsEmpty(ActiveCell) Then
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0,
-16)).Select
Selection.Cut Destination:=ActiveCell.Offset(0,
2).Range("A1:P1")
ActiveCell.Offset(1, 16).Select

Else: ActiveCell.Offset(1, 0).Select
End If
Loop

Range("ak2").Select
Do While Selection.Offset(0, -1) < ""

If IsEmpty(ActiveCell) Then
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0,
-16)).Select
Selection.Cut Destination:=ActiveCell.Offset(0,
2).Range("A1:P1")
ActiveCell.Offset(1, 16).Select

Else: ActiveCell.Offset(1, 0).Select
End If
Loop


End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default Looping through rows and shifting certain contents

I'm trying to think of how you could do it a little quicker. But I haven't
developed the code, but the idea is that it looks like both routines have all
of the same code. So it doesn't matter if you are looking at AJ or AK it
does the same thing. Therefore
you should be able to look at the first cell, do the work you need, if there
is work. Move to the right one cell, do the work you need, then increment
down and to the left however many spaces you have moved to the right. (Might
include some additional variables to keep track of the iterations.) Thus,
you start at Range AJ2 and move to AK M where M is the last row.

Maybe a little cleaner, but if whatcha' got works, good on you.

"Steven" wrote:

OK, I dug in a little more and came up with this solution. It's not a
super fast calculation, but it works faster than I could manually. I
may add something to it to only do the calcs on filtered rows or
something.

Sub MoveBadRows()

Range("aj2").Select

Do While Selection.Offset(0, -1) < ""

If IsEmpty(ActiveCell) Then
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0,
-16)).Select
Selection.Cut Destination:=ActiveCell.Offset(0,
2).Range("A1:P1")
ActiveCell.Offset(1, 16).Select

Else: ActiveCell.Offset(1, 0).Select
End If
Loop

Range("ak2").Select
Do While Selection.Offset(0, -1) < ""

If IsEmpty(ActiveCell) Then
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0,
-16)).Select
Selection.Cut Destination:=ActiveCell.Offset(0,
2).Range("A1:P1")
ActiveCell.Offset(1, 16).Select

Else: ActiveCell.Offset(1, 0).Select
End If
Loop


End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Looping through rows and shifting certain contents

GB

Thanks.

You're totally right. My macro does take a while to run through all of
the rows. I'll give some further thought to your suggestions.

Steve

Reply
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
Rows are shifting slightly when printed Matt Lauer Excel Discussion (Misc queries) 4 October 2nd 09 06:40 PM
Deleting Rows and Shifting Up - Repost D.Parker Excel Discussion (Misc queries) 14 October 11th 07 04:58 AM
Shifting rows into columns biggg_fish Excel Discussion (Misc queries) 2 March 28th 07 03:13 AM
Shifting the contents of cells MTC Setting up and Configuration of Excel 1 August 1st 06 12:10 PM
Shifting Date from all data on one row to several rows ChuckW Excel Discussion (Misc queries) 1 June 8th 05 07:56 PM


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