PDA

View Full Version : Solved: Exporting data to another Workbook



Orange_Wed
07-25-2008, 03:20 PM
Hello All,

I've developed a system to export data from an estimate sheet to an entry sheet.

Well, developed is a bit on the strong side, more like "tried to develop."

What I'm looking at doing is getting the data contained in the estimate sheet (testingpage.xls) to another sheet (template.xls). I only need the data from columns H, I, and a portion of K.

After hours of debugging my code (with no real clue of what i'm doing), I've managed to get the Sub ExportToTemplate to run without errors, but it does nothing.

I'm including the estimate page (testingpage.xls) in this post, as I can only attach one file. Another post will follow with the template.

If someone could take a look at the code for my export button and see what I'm doing wrong, it would be most appreciated.

Any help I can get would be most appreciated.

Thanks in advance,

Wednesday

Orange_Wed
07-25-2008, 03:21 PM
And here's the template.

Thanks again!

RonMcK
07-25-2008, 06:27 PM
Wednesday,

For future reference, you can zip up your files, however many, into one archive file and upload that. .zip is one of the extensions that the website handles nicely. I've forgotten (at the moment) the max size but I think it's on the order of 2MB.

Cheers!

mdmackillop
07-26-2008, 02:54 AM
What is this intended to mean?

If Cells(count & 9) <> 0 Then

I think you mean Cells(count,8).
Changing this, changing = to Like, and adding the Sheet reference "With Source" (not essential but good practice)
This should not only be error free, but should do something!.

Private Sub Export_Click()
Dim template As Worksheet
Dim source As Worksheet
Dim count As Integer
Set template = Workbooks("template.xls").Worksheets("Sheet1")
Set source = Workbooks("testingpage.xls").Worksheets("BUR")
count = 1
With source
Do
If .Cells(count, 8) <> 0 Then
If .Cells(count, 8) Like "L*" Then
template.Cells(count + 1, 1) = .Cells(count, 8)
template.Cells(count + 1, 5) = .Cells(count, 9)
template.Cells(count + 1, 3) = .Cells(count, 11)
template.Cells(count + 1, 1) = .Cells(count, 8)
template.Cells(count + 1, 4) = .Cells(count, 9)
ElseIf .Cells(count, 8) Like "S*" Then
template.Cells(count + 1, 1) = .Cells(count, 8)
template.Cells(count + 1, 6) = Cells(count, 9)
ElseIf .Cells(count, 8) Like "R*" Then
template.Cells(count + 1, 1) = Cells(count, 8)
template.Cells(count + 1, 6) = .Cells(count, 9)
ElseIf .Cells(count, 8) Like "T*" Then
template.Cells(count + 1, 1) = .Cells(count, 8)
template.Cells(count + 1, 8) = .Cells(count, 9)
ElseIf .Cells(count, 8) Like "W*" Then
template.Cells(count + 1, 1) = .Cells(count, 8)
template.Cells(count + 1, 5) = .Cells(count, 9)
ElseIf .Cells(count, 8) Like "P*" Then
template.Cells(count + 1, 1) = .Cells(count, 8)
template.Cells(count + 1, 8) = .Cells(count, 6)
ElseIf .Cells(count, 8) Like "E*" Then
template.Cells(count + 1, 1) = .Cells(count, 8)
template.Cells(count + 1, 8) = .Cells(count, 9)
ElseIf .Cells(count, 8) Like "900" Then
template.Cells(count + 1, 1) = .Cells(count, 8)
template.Cells(count + 1 & 8) = .Cells(count & 9)
End If
End If
count = count + 1
Loop Until count = 100
End With
End Sub



I note that in this section, Lines 1 & 4 are the same, and Col 9 data is being copied twice. I've not looked at any others.

template.Cells(count + 1, 1) = .Cells(count, 8)
template.Cells(count + 1, 5) = .Cells(count, 9)
template.Cells(count + 1, 3) = .Cells(count, 11)
template.Cells(count + 1, 1) = .Cells(count, 8)
template.Cells(count + 1, 4) = .Cells(count, 9)


If there are other issues, let us know.

Orange_Wed
07-28-2008, 11:59 AM
Thanks kindly MD, it worked with your corrections once I added in the Elseif line I somehow removed before sending the file. That was the cause of the doubling-up. My bad.

Thanks again to everyone!

Wednesday