Clear a range of cells

  • Thread starter Thread starter Joe@excel
  • Start date Start date
J

Joe@excel

I have recorded a macro to select and clear a group of cells yet
whenever i ran it, the sheet starts going nuts. but it completes the
task.

is there a way to do it with a code:

example i want to clear
C3 and A14:A37 and d14:d37 and e14:e37 and f14:f37

then i want it to jump to
C41 and A52:A75 and d52:d75 and e52:e75 and f52:f75

then i want it to jump to
C79 and A90:A113 and d90:d113 and e90:e113 and f90:f113

and there are 27 more sets of cells that i want to clear....

can anyone just show me how to create the first 3 codes then i's enter
the rest...

thank you...
 
Sub test()
Dim i As Long
For i = 3 To 1143 Step 38
Cells(i, 3).Clear
Range(Cells(i + 11, 1), Cells(i + 34, 1)).Clear
Range(Cells(i + 11, 5), Cells(i + 34, 5)).Clear
Range(Cells(i + 11, 6), Cells(i + 34, 6)).Clear
Next
End Sub

HTH. Best wishes Harald
 
Think you missed Col D Harald :-)

Sub DelData()
Dim i As Long
For i = 3 To 1143 Step 38
Cells(i, 3).Clear
Cells(i + 11, 1).Resize(24, 1).Clear
Cells(i + 11, 4).Resize(24, 3).Clear
Next
End Sub

And just in the case the OP wants to play, another solution might be:-

Sub DelData1()
Dim i As Long
Dim rng As Range
For i = 3 To 1143 Step 38
Set rng = Union(Cells(i, 3), Cells(i + 11, 1).Resize(24, 1), _
Cells(i + 11, 4).Resize(24, 3))
rng.ClearContents
Next
End Sub

Note also that one uses .Clear vs .ClearContents

One will clear just the data (.ClearContents), whilst the other will clear
data and formatting. You can use either with either.

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 97/00/02/03

------------------------------­------------------------------­----------------
It's easier to beg forgiveness than ask permission :-)
------------------------------­------------------------------­----------------
 
guys!!!! the code works only there's a problem... it saida that it wont
clear any merged cells. and the reason they're merged is because, these
are forms.

gfgd
 
Merged cells are the spawn of the devil!!!!!!!!!!!!!!!!

Why do you need Merged cells for your 'forms'?

Regards
Ken...............
 
Try changing
rng.ClearContents
to
rng.value = ""

(I didn't test it, but it's worked on other routines with merged cells.)
 
Mr. Dave Peterson
you sir, are a life savior... thank you man... you do know the wa
around...
thank you...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top