PC Review


Reply
Thread Tools Rate Thread

Can you use offset and empty in the same code

 
 
jeremiah
Guest
Posts: n/a
 
      22nd Sep 2008
Imported csv causes my headings to be off on the rows as well as the columns.
As part of my code attempting to realign the column headings, I have the
following code to search column B for any instance of a certain word and copy
it to column B of the previous row. I now have 2 rows consecutively that
have that word in it. I need to be able to empty every other instance of the
word beginning at row 3. Is there a way to copy then empty...search again
and copy then empty or does it make more sense to copy all instances and loop
through again and empty every other instance?

Sub MoveGoals()
Dim Cell As Range
For Each Cell In Range("B:B")
If Cell.Value = "GOALS" Then
Cell.Offset(-1, 0) = "GOALS"
End If
Next Cell
End Sub
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      22nd Sep 2008
If I were doing it, I would empty as I go. Assuming you really intend to move
the found data up one row:

Sub MoveGoals()
Dim Cell As Range
For Each Cell In Range("B:B")
If UCase(Cell.Value) = "GOALS" Then
Cell.Cut Cell.Offset(-1, 0)
End If
Next Cell
Application.CutCopyMode = False
End Sub

You might want to run this on a test sheet first.



"jeremiah" wrote:

> Imported csv causes my headings to be off on the rows as well as the columns.
> As part of my code attempting to realign the column headings, I have the
> following code to search column B for any instance of a certain word and copy
> it to column B of the previous row. I now have 2 rows consecutively that
> have that word in it. I need to be able to empty every other instance of the
> word beginning at row 3. Is there a way to copy then empty...search again
> and copy then empty or does it make more sense to copy all instances and loop
> through again and empty every other instance?
>
> Sub MoveGoals()
> Dim Cell As Range
> For Each Cell In Range("B:B")
> If Cell.Value = "GOALS" Then
> Cell.Offset(-1, 0) = "GOALS"
> End If
> Next Cell
> End Sub

 
Reply With Quote
 
jeremiah
Guest
Posts: n/a
 
      23rd Sep 2008
Exactly. Thanks again, it works perfectly.

"JLGWhiz" wrote:

> If I were doing it, I would empty as I go. Assuming you really intend to move
> the found data up one row:
>
> Sub MoveGoals()
> Dim Cell As Range
> For Each Cell In Range("B:B")
> If UCase(Cell.Value) = "GOALS" Then
> Cell.Cut Cell.Offset(-1, 0)
> End If
> Next Cell
> Application.CutCopyMode = False
> End Sub
>
> You might want to run this on a test sheet first.
>
>
>
> "jeremiah" wrote:
>
> > Imported csv causes my headings to be off on the rows as well as the columns.
> > As part of my code attempting to realign the column headings, I have the
> > following code to search column B for any instance of a certain word and copy
> > it to column B of the previous row. I now have 2 rows consecutively that
> > have that word in it. I need to be able to empty every other instance of the
> > word beginning at row 3. Is there a way to copy then empty...search again
> > and copy then empty or does it make more sense to copy all instances and loop
> > through again and empty every other instance?
> >
> > Sub MoveGoals()
> > Dim Cell As Range
> > For Each Cell In Range("B:B")
> > If Cell.Value = "GOALS" Then
> > Cell.Offset(-1, 0) = "GOALS"
> > End If
> > Next Cell
> > End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I modify my code to offset the defined range and repeat theprocedure instead of duplicating my code? najisaadat@gmail.com Microsoft Excel Programming 4 29th May 2009 10:13 PM
Dynamic Chart (OFFSET Function) plots empty cells. SJ Microsoft Excel Charting 3 7th Aug 2008 06:14 PM
How do i write an offset code ? Corey Microsoft Excel Programming 12 4th Jan 2007 12:18 AM
ActiveCell.Offset Code workerboy Microsoft Excel Programming 2 10th Aug 2006 02:23 PM
Offset Code Todd Huttenstine Microsoft Excel Programming 7 5th Dec 2003 03:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:37 AM.