MAYANK PATADIYA
MAYANK PATADIYA

Reputation: 1

excel vba data transfer from one sheet to another error only title copy no any data

excel vba data transfer from one sheet to another error only title copy no any data Here is the code

Sub transferData()
    Application.ScreenUpdating = False
    'Dim myData As Worksheet, ItemA As Worksheet, ItemB As Worksheet, ItemC As Worksheet, ItemD As Worksheet, ItemE As Worksheet
    Dim Item As String
    Dim price As Long, Quantity As Long
    Dim r1 As Long, erow As Long
    r1 = 1

    Sheets(Array("Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6")).Select
       Sheets("Sheet2").Activate
       ActiveSheet.Cells.Select
       Selection.Clear

    Sheets(Array("Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6")).Select
        Sheets("Sheet2").Activate
        Sheets("Sheet2").Range("A1").Select
        ActiveCell.Value = "Item"
        Sheets("Sheet2").Range("B1").Select
        ActiveCell.Value = "price"
        Sheets("Sheet2").Range("C1").Select
        ActiveCell.Value = "Quantity"

    myData.Activate

    Do While Cells(r1, 1) <> ""
    Item = Cells(r1, 2).Value
    r1 = r1 + 1
    price = Cells(r1, 2).Value
    r1 = r1 + 1
    qty = Cells(r1, 2)
    r1 = r1 + 1

    p = Worksheets.Count
    For q = 1 To p
    If ActiveWorkbook.Worksheets(q).CodeName = UCase(ItemName) Then
    Worksheets(q).Activate
    erow = Worksheets(q).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    Cells(erow, 1).Value = ItemName
    Cells(erow, 2).Value = price
    Cells(erow, 3).Value = qty
    End If
    Next q
    myData.Activate
    Loop
    Application.ScreenUpdating = True
    End Sub

Upvotes: 0

Views: 93

Answers (1)

Gary&#39;s Student
Gary&#39;s Student

Reputation: 96773

The worksheet variable myData is neither Dimed nor Set.
The variable ItemName is used but never assigned a value.

There may be other problems

Upvotes: 1

Related Questions