Clear contents macro
Dave,
Here's an example:
Dim r As Integer, c As Integer, blank As Boolean
For r = 2 To 176
blank = True
For c = 1 To 10
If ActiveSheet.Cells(r, c).Value < "" Then
blank = False
Exit For
End If
Next c
If blank Then Exit For
Next r
The first "for" loop sets the boundaries of the search from row 2 to row
176. We make the assumption that the row is blank (3rd line) and then the
second "for" loop tests this assumption by examining the first 10 columns of
the row. If any cell in the first 10 columns is not blank, the assumption
is disproved and we go on to examine the next row. At the end of this code,
if "blank" is True then "r" is the number of the first blank row. If
"blank" is False then we did not find any blank rows.
Luke
"Dave" wrote in message
...
Hi Luke
Thanks for your reply.
As I said I'm not very good with VBA,but I think I need a little loop to
search
for the first blank row after the populated rows, and can you help with
the
coding please.
Thanks once again
Regards
Dave
"Luke Alcatel" wrote:
I don't understand how an operation you perform on the worksheet after
you
import data can affect the imported data but that might be my problem.
Seems to me that you don't want to hard code row 175 as an upper bound
but
instead preface your code with a little loop that searches for the first
fully blank row that follows your poplulated rows. Does that sound OK
or do
you still need to know how to write such a loop?
Luke
"Dave" wrote in message
...
Hi
I have a macro that clears the contents of a sheet after I have
imported the data into a database.
This works fine but if the data is less then 175 rows it leaves
blank rows in the database.
How can I get round this.
Not very good with VBA would appreciate any help
Macro as below:-
Range("A2:N175").select
Selection.ClearContents
Range("A2").Select
Workbooks("MyBook1.xls").Close SaveChange:=True
|