Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Question 2

Status
Not open for further replies.

haeddy

Technical User
Mar 5, 2010
22
US
I'm trying to do total compensation report for our employees. I've created a database in Excel and I created the letter in excel. How can I merge the two files to create the letters? I have Excel 2013.

 
Ok - got through that one. Now it says "Run time error 91: object variable or with block variable not set" on With wsdata.cells (1,1).current region.

 
Please post your code.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Function RangeName(sName As String) As String
RangeName = Application.Substitute(sName, " ", "_")
End Function
Sub MergePrint()
Dim wsForm As Worksheet, wsData As Worksheet
Dim sRngName As String, r As Long, c As Integer
Set wsData = Workbooks("Total Compensation Summary_dteztz.xlsx").Worksheets("EE Upload")
With wsData.Cells(1, 1).CurrentRegion
For r = 2 To .Rows.Count
If Not wsData.Cells(r, 1).EntireRow.Hidden Then
For c = 2 To .Columns.Count
sRngName = wsData.Cells(1, c).Value
Range(RangeName(sRngName)).Value = wsData.Cells(r, c).Value
Next
wsForm.PrintOut
End If
Next
End With
End Sub


 
Where have you SET wsForm?

Com'on, please check your code before you run. Use the Debug Window to determine where the code ends. It did not error on the statement you stated.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I swear the error was on that statement and I do Debug. I don't know what happened because it's on another one now and I didn't change anything. When I put the SET ws Form in front of the Set wsdata it says subscript out of range.
 
Subscript out of range is probably a spelling error in the workbook name or the worksheet name.

Do you have any trailing SPACE, for instance?

Look VERY carefully!

Due diligence is required by you.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thank you for all your patience and assistance. One last question - is it possible to have it sent to a file instead of the printer?
 
Short answer - yes.
Longer answer - start your macro recorder, "sent to a file", stop recorder, look at the code generated.

BTW, don't you think Skip deserves a star for all his help?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
wsForm.Parent.Save

The parent object of the sheet is a workbook. You might want to .SaveAs to some other workbook name or as some other file format.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I think the reason it wasn't working is because they were separate workbooks. When I figured out I had to add the data as a sheet to the form workbook it worked.

And yes - he deserves a big star!
 
Thx! Enjoyed the challenges.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top