Macro to copy column data into another worksheet till the last row of data in the source sheet

I am trying to copy data from source sheet to another sheet TILL the LAST ROW OF DATA. How can I limit macro till the last row of data. Below is the macro that is created to get the data.

' Sub ABringData() ' ' BringData Macro ' ' Sub ABringData()

Columns("G:G").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("G1").Select
ActiveCell.FormulaR1C1 = "=Data!RC[-4]"
Range("G2").Select
Columns("G:G").EntireColumn.AutoFit
Range("G1").Select
Selection.AutoFill Destination:=Range("G:G")
Range("G:G").Select
Columns("G:G").EntireColumn.AutoFit
Columns("G:G").Select
With Selection.Font
    .Color = -16776961
    .TintAndShade = 0
End With
Columns("AA:AA").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("AA1").Select
ActiveWindow.SmallScroll ToRight:=1
ActiveCell.FormulaR1C1 = "=Data!RC[-20]"
Range("AA1").Select
Selection.AutoFill Destination:=Range("AA:AA")
Range("AA:AA").Select
With Selection
    .HorizontalAlignment = xlLeft
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
End With
With Selection.Font
    .Color = -16776961
    .TintAndShade = 0
End With
ActiveWindow.SmallScroll ToRight:=-12
Columns("G:G").Select
With Selection
    .HorizontalAlignment = xlLeft
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
End With
Range("G4").Select

End Sub

Answers


Sub ABringData()

'************* Add this ***************
Dim intLastRow As Integer
Dim strRange As String

intLastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'************** End Add ****************


Columns("G:G").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("G1").Select
ActiveCell.FormulaR1C1 = "=Data!RC[-4]"
Range("G2").Select
Columns("G:G").EntireColumn.AutoFit
Range("G1").Select

'************* Add this ***************
strRange = "G1:G" & intLastRow
Selection.AutoFill Destination:=Range(strRange)
 '************** End Add ****************

Range("G:G").Select
Columns("G:G").EntireColumn.AutoFit
Columns("G:G").Select

With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With

Columns("AA:AA").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("AA1").Select
ActiveWindow.SmallScroll ToRight:=1
ActiveCell.FormulaR1C1 = "=Data!RC[-20]"
Range("AA1").Select

'************* Add this ***************
strRange = "AA1:AA" & intLastRow
Selection.AutoFill Destination:=Range(strRange)
'************** End Add ****************

Range("AA:AA").Select

With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With

ActiveWindow.SmallScroll ToRight:=-12
Columns("G:G").Select

With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

Range("G4").Select

End Sub

Need Your Help

Efficient way of finding max in 1d array using pthreads in C

c arrays linux pthreads max

I want to find the maximum value in 1d array using pthreads in C.

Strange behaviour of AndAR(r205) sample code "nmatsui / AR_Speeker" on Android Studio

java android eclipse andar

I've tried to replicate/migrade, the AndAR sample code Mr. Nobuyuki Matsui uploaded on GitHub, the "nmatsui / AR_Speeker", which can be downloaded from here, and I get a strange behaviour on Android