Macros

manfromearth

New Member
Joined
Jun 2, 2011
Messages
1
We used the following code to copy particular cells from a worksheet, but we are not able to copy those blank spaces to preserve the integrity of the table...can u pls help?

Function LastColumn() As Long<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Dim ix As Long<o:p></o:p>
ix = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.Count<o:p></o:p>
LastColumn = ix<o:p></o:p>
<o:p></o:p>
End Function<o:p></o:p>
Function ColNo2ColRef(colNo As Integer) As String<o:p></o:p>
If colNo < 1 Or colNo > 256 Then<o:p></o:p>
ColNo2ColRef = "#VALUE!"<o:p></o:p>
Exit Function<o:p></o:p>
End If<o:p></o:p>
ColNo2ColRef = Cells(1, colNo).Address(True, False, xlA1)<o:p></o:p>
ColNo2ColRef = Left(ColNo2ColRef, InStr(1, ColNo2ColRef, "$") - 1)<o:p></o:p>
End Function<o:p></o:p>
<o:p> </o:p>
Sub MainMacro()<o:p></o:p>
<o:p> </o:p>
Dim colNo As Integer<o:p></o:p>
Dim i As Integer<o:p></o:p>
Dim reftext As String<o:p></o:p>
Dim reftext1 As String<o:p></o:p>
Dim rCount As Long<o:p></o:p>
<o:p> </o:p>
rCount = Range("C" & Rows.Count).SpecialCells(xlCellTypeLastCell).Row<o:p></o:p>
<o:p> </o:p>
For i = 7 To rCount Step 29<o:p></o:p>
Sheets("Pinnacle Metrics by Projects").Range("C" & i).Copy Destination:=Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>
Sheets("Pinnacle Metrics by Projects").Range("D" & i).Copy Destination:=Sheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>
Next i<o:p></o:p>
<o:p> </o:p>
For i = 11 To rCount Step 29<o:p></o:p>
Sheets("Pinnacle Metrics by Projects").Range("H" & i).Copy Destination:=Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>
Sheets("Pinnacle Metrics by Projects").Range("H" & i + 1).Copy Destination:=Sheets("Sheet1").Range("D" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>
Next i<o:p></o:p>
<o:p> </o:p>
'Calculating the last cloumn<o:p></o:p>
colNo = LastColumn() - 2<o:p></o:p>
reftext = ColNo2ColRef(colNo)<o:p></o:p>
reftext1 = ColNo2ColRef(colNo - 2)<o:p></o:p>
<o:p> </o:p>
'Customer Profitability latest month<o:p></o:p>
For i = 12 To rCount Step 29<o:p></o:p>
Sheets("Pinnacle Metrics by Projects").Range(reftext1 & i).Copy Destination:=Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>
Next i<o:p></o:p>
<o:p> </o:p>
'Customer Profitability YTD<o:p></o:p>
For i = 12 To rCount Step 29<o:p></o:p>
Sheets("Pinnacle Metrics by Projects").Range(reftext & i).Copy Destination:=Sheets("Sheet1").Range("D" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>
Next i<o:p></o:p>
'Utilisation Onsite<o:p></o:p>
For i = 13 To rCount Step 29<o:p></o:p>
Sheets("Pinnacle Metrics by Projects").Range(reftext & i).Copy Destination:=Sheets("Sheet1").Range("E" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>
Next i<o:p></o:p>
'Utilisation Offshore<o:p></o:p>
For i = 14 To rCount Step 29<o:p></o:p>
Sheets("Pinnacle Metrics by Projects").Range(reftext & i).Copy Destination:=Sheets("Sheet1").Range("F" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>
Next i<o:p></o:p>
'Span Onsite<o:p></o:p>
For i = 32 To rCount Step 29<o:p></o:p>
Sheets("Pinnacle Metrics by Projects").Range(reftext & i).Copy Destination:=Sheets("Sheet1").Range("G" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>
Next i<o:p></o:p>
'Span Offshore<o:p></o:p>
For i = 31 To rCount Step 29<o:p></o:p>
Sheets("Pinnacle Metrics by Projects").Range(reftext & i).Copy Destination:=Sheets("Sheet1").Range("H" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>
Next i<o:p></o:p>
<o:p> </o:p>
End Sub<o:p></o:p>
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Sheets("Pinnacle Metrics by Projects").Range("C" & i).Copy Destination:=Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

Destination:=Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1)<o:p></o:p>

End(xlUp).Offset(1) would this bit ( which appears to find the bottom used cell in the destination sheet) be by passing empty cell you've just pasted ??
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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