I have a master sheet (CMRDETAILS) im taking specific data from certain columns of two other sheets (HistoricalData)(ImportData) and copying it across into the master sheet
Im trying and failing to find the loop to find the last empty cell and enter the data into that row and the empty ones that follow it, the first set of data i move is historical, then copy and paste from Importdata
Is there anyway once knowing the range to set the pasting range to utalise the count?
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim filter As String
Dim targetWorkbook As Workbook, wb As Workbook
Dim Ret As Variant
Dim Caption As String
Dim LR2 As Long
Dim LR1 As Long
Dim LastCell As Range
Dim LastCellColRef As Long
Worksheets("ImportData").Cells.Clear
Set targetWorkbook = Application.ActiveWorkbook
filter = "Text files (*.CSV),*.CSV"
Caption = "Please Select an input file "
Ret = Application.GetOpenFilename(filter, , Caption)
If Ret = False Then Exit Sub
Set wb = Workbooks.Open(Ret)
wb.Sheets(1).UsedRange.Copy targetWorkbook.Worksheets("ImportData").Range("A1")
wb.Close SaveChanges:=False
Set ws = ThisWorkbook.Sheets("ImportData")
Worksheets("ImportData").Range("D:D").EntireColumn.Insert Shift:=xlToRight
Worksheets("ImportData").Range("D1").Value = "Month"
LR1 = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
LR2 = ws.Range("D" & ws.Rows.Count).End(xlUp).Row + 1
ws.Range("D" & LR2 & ":D" & LR1).FormulaR1C1 = "=TEXT(R[0]C[-1], ""mmm"")"
Sheets("HistoricalData").Range("AE2:AE51").Copy Sheets("CmrDetails").Range("B2:B51")
Sheets("HistoricalData").Range("D2:D51").Copy
Sheets("CmrDetails").Range("A2:A51").PasteSpecial xlPasteValues
Sheets("HistoricalData").Range("Z2:Z51").Copy Sheets("CmrDetails").Range("c2:c51")
LastCellColRef = 1 'column number to look in when finding last cell
Set LastCell = Sheets("CmrDetails").Cells(Rows.Count, LastCellColRef).End(xlUp).Offset(1, 0)
MsgBox LastCell.Address 'just to verify the count is working
Sheets("ImportData").Range("X2:X350").Copy Sheets("CmrDetails").Range("B52:B350") 'this is the data is want to copy to the empty row
Sheets("ImportData").Range("D2:D51").Copy 'this is the data is want to copy to the empty row
Sheets("CmrDetails").Range("A52:A350").PasteSpecial xlPasteValues 'this is the data is want to copy to the empty row
Sheets("ImportData").Range("AX2:AX350").Copy Sheets("CmrDetails").Range("c52:c350") 'this is the data is want to copy to the empty row
Application.CutCopyMode = False
Sheets("CmrDetails").Range("C2:C350").EntireColumn.Hidden = True
Set ws = ThisWorkbook.Sheets("NPS")
Set LastCell = Nothing
MsgBox ("Upload Complete")
End Sub
no errors I just cant figure out the logic