Deleting Rows in cycle

jose001

Board Regular
Joined
Mar 27, 2006
Messages
103
Hi all,

Could anyone help me clean this code up a little. It basically cycles through my sheets and pulls out data from certain cells.and puts it in the actions sheet.

Sub TransferData()
Dim i As Long: i = 6
For Each sh In Worksheets
If sh.Name <> "Actions" Then
Worksheets("Actions").Range("B" & i).Value = sh.Range("A2").Value
Worksheets("Actions").Range("C" & i).Value = sh.Range("B2").Value
i = i + 1
End If
Next sh
End Sub

However, I would like to add somthing like this in which will clear whatever is in the cells in actions already...

Range("B3:G500").Select
Selection.ClearContents

Sadly I'm very bad with VB and have no idea where to put it (if it is even the correct thing to do) without it wiping before it goes through the next sheet. Also I would really like to put a horizontal line under each entry from say B to G. Any help would be reaaaaally appreciated!

Jose
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi
try putting the code Range("B3:G500").ClearContents before For Each sh This will clear the contents before cycle starts and be ready to receive new data
Ravi
 
Upvote 0
Thanks Ravi, thats wicked, works a treat! How can I exclude another sheet called summary from this cycle?
 
Upvote 0
OK Iv sorted this one now, found the parameter, anyone have any ideas how I can draw a line under each entry from b to g and colour each new row (btoG) with a different colour?

Jose
 
Upvote 0
Hi
Try. Add these codes before i = i +1

Code:
Worksheets("Actions").Range("B" & i).interior.colorindex = i
Worksheets("Actions").Range("B" & i).select
 With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
Ravi
 
Upvote 0
That works brillaint Ravi but it only colours the cells in column B. Is there are way to colour the whole row from B to G? I'm guessing its something like...


Worksheets("Actions").Range("B" & i : "G" & i).Select

but I don't know the proper parameter

Thanks very much for your help!

Jose
 
Upvote 0
Ok I found the parameter, just one final query, it is underlining any cell which is selected in the worksheet, how could I alter the code to only underline the cells b to g? and also maybe clear the colours and underline when it restarts?

Sub TransferData()
Dim i As Long: i = 6
Range("B6:G500").ClearContents
For Each sh In Worksheets
If sh.Name <> "Actions" And sh.Name <> "summary" Then
Worksheets("Actions").Range("B" & i).Value = sh.Range("A2").Value
Worksheets("Actions").Range("C" & i).Value = sh.Range("B2").Value
Worksheets("Actions").Range("b" & i & ":g" & i).Interior.ColorIndex = 1 + i
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
i = i + 1
End If
Next sh
End Sub

Thanks in advance
 
Upvote 0
Hi
insert these codes before With Selection.Borders

Code:
x = "b" & i & ":g" & i
Range(x).Select
Range(x).interior.colorindex = x1None

RAvi
 
Upvote 0

Forum statistics

Threads
1,214,413
Messages
6,119,372
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top