简体   繁体   中英

How to copy column data from one sheet and then copy that to another sheet in vba excel

I need help with this small project. What I need to accomplished this task is the following:

I have a excel file where my macro button once clicked will read the data from a sheet1 only in column A then should throw the data to another sheet2 and move every data from the sheet1 to sheet2 and display all the data to each separate column.

here is a image of the data example. in the image every circle needs to be in its own column to the new sheet2 that is only part of the data the total of the column rows is around 900.

if need more information please let me know.

在此处输入图片说明

here is the code I have it copy the sheet from sheet1 to sheet2 but I need the rest to work

Sub ExportFile()
Dim strValue As String
Dim strCellNum As String
Dim x As String
x = 1

For i = 1 To 700 Step 7
    strCellNum = "A" & i
    strValue = Worksheets("data").Range(strCellNum).Value
    Debug.Print strValue
    Worksheets("NewData").Range("A" & x).Value = strValue
    x = x + 1
Next
End Sub

you can try this:

Sub ExportFile()
    Dim area As Range
    Dim icol As Long

    With Worksheets("data")
        With .Range("A1", .Cells(.Rows.Count, 1).End(xlUp)).SpecialCells(xlCellTypeConstants)
            For Each area In .Areas
                icol = icol + 1
                Worksheets("NewData").Cells(1, icol).Resize(area.Rows.Count).Value = area.Value
            Next
        End With
    End With
End Sub

Give this a try:

Sub DataReorganizer()
    Dim s1 As Worksheet, s2 As Worksheet, N As Long, i As Long, j As Long, k As Long
    Dim v As Variant

    Set s1 = Sheets("Data")
    Set s2 = Sheets("NewData")

    N = s1.Cells(Rows.Count, "A").End(xlUp).Row
    For i = N To 2 Step -1
        If s1.Cells(i, "A").Value = "" And s1.Cells(i - 1, "A").Value = "" Then s1.Cells(i, "A").Delete shift:=xlUp
    Next i

    j = 1
    k = 1
    N = s1.Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To N
        v = s1.Cells(i, "A").Value
        If v = "" Then
            j = 1
            k = k + 1
        Else
            s2.Cells(j, k).Value = v
            j = j + 1
        End If
    Next i

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM