0

My excel workbook contains a "Raw Data" sheet with a macro-assigned button. I want to parse the data in that sheet into corresponding sheets that has accompanying graphs in them after pressing the button. Below is the code that I am working on:

Public maxVoltage As Long
Public rowCount As Long

Sub RunAllMacros()
    getData
    parseData
End Sub

Sub getData()
    Application.ScreenUpdating = False

    maxVoltage = InputBox("Input nominal voltage (V).")

    Range("B2").Select
    Range(Selection, Selection.End(xlDown)).Select
    rowCount = Selection.Count + 1

    Application.ScreenUpdating = True
End Sub

Sub parseData()
    Application.ScreenUpdating = False

    Worksheets("Raw Data").Range(Cells(2, 2), Cells(rowCount, 2)).Copy _
        Destination:=Worksheets("Voltage and Current").Range(Cells(2, 1), Cells(rowCount, 1))

    Application.ScreenUpdating = True
End Sub

The getData() function is used to count the number of rows in the "Raw Data" sheet because the number of data may vary. The data will start in Column B with the top row serving as headings or names for the data. So the data will start in the 2nd row. My problem is that the syntax I use to copy and paste the data from the "Raw Data" sheet to the "Voltage and Current" sheet gives me Error 400. I do not know if this syntax does not accept variables as arguments in the 'Range' object. I will appreciate any help.

VBA Pete
  • 2,656
  • 2
  • 24
  • 39
  • 1
    You need to fully qualify all your calls to `Cells` and `Range` with the worksheet they're referring to instead of using the globals. – Comintern Jan 10 '17 at 01:17
  • What do you mean fully qualify my calls? Do I need to explicitly activate the corresponding worksheets before I am able to parse the data from one sheet to another? – AJ De Guzman Jan 10 '17 at 01:20
  • No, you need to add the worksheet. I.e. `Worksheets("Raw Data").Range(Worksheets("Raw Data").Cells(2, 2), Worksheets("Raw Data").Cells(RowCount, 2)).Copy` – Comintern Jan 10 '17 at 01:21
  • try `Worksheets("Raw Data").Range("B2:B" & rowCount).Copy _ Destination:=Worksheets("Voltage and Current").Range("A2")` – nightcrawler23 Jan 10 '17 at 01:21
  • Thanks Comintern! That solution worked well. Thank you too nightcrawler23. Have a nice day! – AJ De Guzman Jan 10 '17 at 01:24

0 Answers0