Hi, I have the following code that imports data to the main sheet. However, I would like to have it import it to a different worksheet within the same workbook.
When I want to import it to a different worksheet (named "Report") what code do I use?
I tried:
It imported the column headings correclty, but I got the error "Run-time error '1004': Method 'Range' of object '_Worksheet' failed". None of the other data was imported.
What am I doing wrong? I am as novice as you can get to VBA code.
Thanks,
Mike
“Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.”-Albert Einstein
Code:
' Import slotdata onto worksheet
For iCols = 0 To SlotData.Fields.Count - 1
Cells(19, iCols + 4).Value = SlotData.Fields(iCols).Name
Next
Range(Cells(19, 1), _
Cells(19, SlotData.Fields.Count)).Font.Bold = False
Range("D20").CopyFromRecordset SlotData
When I want to import it to a different worksheet (named "Report") what code do I use?
I tried:
Code:
' Import slotdata onto worksheet
For iCols = 0 To SlotData.Fields.Count - 1
Worksheets("Report").Cells(19, iCols + 4).Value = SlotData.Fields(iCols).Name
Next
Range(Worksheets("Report").Cells(19, 1), _
Cells(19, SlotData.Fields.Count)).Font.Bold = False
Range("D20").CopyFromRecordset SlotData
It imported the column headings correclty, but I got the error "Run-time error '1004': Method 'Range' of object '_Worksheet' failed". None of the other data was imported.
What am I doing wrong? I am as novice as you can get to VBA code.
Thanks,
Mike
“Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.”-Albert Einstein