Moving Column Data to another sheet using VBA

Seldrich

New Member
Joined
May 11, 2014
Messages
20
Hello,
I am moving data with VBA from 1 sheet to another and for the most part it works great. All the data is moved and is where i need it to be. The problem with one of the columns is that somehow the format is changed and the change causes my other reference to break. Below is the VBA i am using.

Code:
Sub MoveData()

    Dim lastRow As Long
'DATALINK
    lastRow = Sheets("Raw Data").Range("A" & Rows.Count).End(xlUp).Row
    Sheets("DATA").Range("A2:A" & lastRow).Value = Sheets("Raw Data").Range("A2:A" & lastRow).Value
'AGENT
    lastRow = Sheets("Raw Data").Range("B" & Rows.Count).End(xlUp).Row
    Sheets("DATA").Range("B2:B" & lastRow).Value = Sheets("Raw Data").Range("B2:B" & lastRow).Value
'DIRECTOR
    lastRow = Sheets("Raw Data").Range("E" & Rows.Count).End(xlUp).Row
    Sheets("DATA").Range("C2:C" & lastRow).Value = Sheets("Raw Data").Range("E2:E" & lastRow).Value
'CENTER
    lastRow = Sheets("Raw Data").Range("F" & Rows.Count).End(xlUp).Row
    Sheets("DATA").Range("D2:D" & lastRow).Value = Sheets("Raw Data").Range("F2:F" & lastRow).Value
 'SURVEY   
    lastRow = Sheets("Raw Data").Range("G" & Rows.Count).End(xlUp).Row
    Sheets("DATA").Range("E2:E" & lastRow).Value = Sheets("Raw Data").Range("G2:G" & lastRow).Value
'REP SAT    
    lastRow = Sheets("Raw Data").Range("H" & Rows.Count).End(xlUp).Row
    Sheets("DATA").Range("F2:F" & lastRow).Value = Sheets("Raw Data").Range("M2:M" & lastRow).Value
    


    
End Sub

the problem is that the last part of the script for moving G2:G to M2:M i need the data to read this way[TABLE="width: 64"]
<tbody>[TR]
[TD="class: xl65, width: 64"]+5 Highly satisfied[/TD]
[/TR]
[TR]
[TD="class: xl65"]+3[/TD]
[/TR]
[TR]
[TD="class: xl65"]+5 Highly satisfied[/TD]
[/TR]
[TR]
[TD="class: xl65"]+5 Highly satisfied[/TD]
[/TR]
[TR]
[TD="class: xl65"]+4[/TD]
[/TR]
</tbody>[/TABLE]

but instead the data is changed to read this way
[TABLE="width: 64"]
<tbody>[TR]
[TD="class: xl65, width: 64"]+5 Highly satisfied[/TD]
[/TR]
[TR]
[TD="class: xl65"] 3[/TD]
[/TR]
[TR]
[TD="class: xl65"]+5 Highly satisfied[/TD]
[/TR]
[TR]
[TD="class: xl65"]+5 Highly satisfied[/TD]
[/TR]
[TR]
[TD="class: xl65"] 4[/TD]
[/TR]
</tbody>[/TABLE]


and breaks my reference =ABS(MID(F2,2,1)) on my output table.


Thanks for the help! and if i did not explain well enough i can put something in a drop
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
This should do the trick

Sub HideRows()
Dim lastRow As Integer, Col As Integer, Row As Integer
lastRow = Sheets("Raw Data").Range("A" & Rows.Count).End(xlUp).Row
For Col = 1 To 6
For Row = 2 To lastRow
Sheets("DATA").Cells(Row, Col).Value = "'" & Sheets("Raw Data").Cells(Row, Col).Value
Next Row
Next Col
End Sub
 
Upvote 0
Try this:

Code:
Sub MoveData()
Application.ScreenUpdating = False
Dim Del As Variant
Dim lastRow As Long
Dim x As Long
Del = Array("A", "B", "E", "F", "G", "M")
x = 1
    For i = 0 To 5
        lastRow = Sheets("Raw Data").Cells(Rows.Count, Del(i)).End(xlUp).Row
        Sheets("Raw Data").Range(Del(i) & "2" & ":" & Del(i) & lastRow).Copy Sheets("DATA").Cells(2, x)
        x = x + 1
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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