View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Clearing contents from a range

That is strange. I tested the code before I posted it and it worked fine for
me. Based on Jim's response to one of my other posts in this thread, I
gather my code worked fine for him also. Out of curiosity, what error
message did you get when you ran my code (after changing the worksheet name
to one of your own worksheet names)?

--
Rick (MVP - Excel)


"G. Yamada" wrote in message
...
Hi Rick,

I did try your code, but it appeared that it kept stopping where the
worksheet name was indicated. I changed this according to what worksheet
I
was in, but it continued to produce an error. Thank you for the help
nonetheless.

"Rick Rothstein" wrote:

Not that I am knocking Jim's code because (with the change Roger
suggested)
it should work fine; but I was wondering, did you even try my posted
code?
Just so you know, it works too.

--
Rick (MVP - Excel)


"G. Yamada" wrote in message
...
Hello,

Thank you for you reply. This almost does the trick for me. I need to
have
all the columns in the row (to be cleared) at least up to column Q to
be
cleared. So far, the program you provided only clears columns D and E.
If
you could revise the program to reflect this change, I would sincerly
appreciate it. Thank you so much for providing this. I have put many
hours
into it already and should have turned to the forum much earlier.

P.S. Is there a fast and efficient way to learn VBA for Excel?

"Jim Thomlinson" wrote:

Try this...

Sub ClearStuff()
Dim rngAll As Range
Dim rngArea As Range

On Error Resume Next
Set rngAll = Range("D:D").SpecialCells(xlCellTypeConstants)
If Not rngAll Is Nothing Then
For Each rngArea In rngAll.Areas
If rngArea.Cells.Count 1 Then
Range(rngArea.Cells(1), _
rngArea.Cells(rngArea.Count - 1).Offset(0, 1)).ClearContents
End If
Next rngArea
End If
End Sub
--
HTH...

Jim Thomlinson


"G. Yamada" wrote:

Hello,

I am completely new to Excel VBA and I have a task that can only be
done
using it. I need to format a group of orders to upload them.
Essentially I
start with:

78693624286 1 9.71 2793888 ....
02761688770 1 2.99 2793888
...

02454352960 1 8.45 2792280
...
02454352959 1 8.45 2792280
...

78693675842 1 8.65 2791190
...
02454305295 1 21.86 2791190
...
78693614475 1 7.25 2791190
...
04339614171 1 9.77 2791190
...

08536513892 1 3.99 2791055
..


What I want to end up with is:

78678693286 1 9.71
02761688770 1 2.99 2793888
...

02454352960 1 8.45
02454352959 1 8.45 2792280
...

78693675842 1 8.65
02454305295 1 21.86
78693614475 1 7.25
04339614171 1 9.77 2791190
...

08536513892 1 3.99 2791055
...


The orders are separated by an empty row (which is already done for
me)
according to the order numbers in the D column (numbers starting
with
279...). Each order may have 1 or more items designated by the item
number
in the first column. As you can see, the first three orders
(groups)
have
more than one item in the order. These are what have been causing
an
issue
for me. I need to clear the information from the D column onwards
(including
D) on the item lines (rows) which are part of the same order EXCEPT
for
the
last line in the order as shown above. I would sincerely appreciate
any
help.