macro to copy data on a loop until a blank row is hit errors

exhatcher

New Member
Joined
Jun 7, 2016
Messages
3
I am trying to write a macro with VBA that will copy the data from my table in a sheet tiled "Front End" to a table on another sheet called "Raw Data". here is my code so far for the copying and pasting into the other sheet in the next empty row. I keep getting error that says "application defined or object defined error" at the copy/paste statements that have an X in place of the row name in an attempt to change the row with each loop.

Code:
Sub transfer()    Dim x As Long
'set starting point at row 8
    x = 8
    Dim BlankFound As Boolean
'defines the sheet the data is being coppied from
    Dim sourceSheet As Worksheet: Set sourceSheet = ThisWorkbook.Worksheets("Front End")
'defines the sheet the data is being pasted into
    Dim destSheet As Worksheet: Set destSheet = ThisWorkbook.Worksheets("Raw Data")
    
    Do While BlankFound = False
        
'selects the next row where the 1st column is empty
        lMaxRows = destSheet.Cells(destSheet.Rows.Count, "A").End(xlUp).Row
'pastes the data from the specified cells into the next empty row
        destSheet.range("A" & lMaxRows + 1).Value = sourceSheet.range("C2").Value
        destSheet.range("M" & lMaxRows + 1).Value = sourceSheet.range("E2").Value
        destSheet.range("N" & lMaxRows + 1).Value = sourceSheet.range("E4").Value
        destSheet.range("P" & lMaxRows + 1).Value = sourceSheet.range("G4").Value
        destSheet.range("Q" & lMaxRows + 1).Value = sourceSheet.range("C4").Value
        destSheet.range("O" & lMaxRows + 1).Value = sourceSheet.range("I3").Value
        destSheet.range("B" & lMaxRows + 1).Value = sourceSheet.range("Ix").Value
        destSheet.range("C" & lMaxRows + 1).Value = sourceSheet.range("Jx").Value
        destSheet.range("D" & lMaxRows + 1).Value = sourceSheet.range("Kx").Value
        destSheet.range("E" & lMaxRows + 1).Value = sourceSheet.range("Lx").Value


        x = x + 1
        If Cells(x, "K").Value = "" Then
        BlankFound = True
        End If
     Loop
End Sub
any help is greatly appreciated, my main issue is i cant figure out how to get the row number in the copy/paste statement to change after each loop
 

Forum statistics

Threads
1,081,860
Messages
5,361,734
Members
400,652
Latest member
cortexnotion

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top