I have a macro that works fine but I must run it on each sheet. I had a friend write the macro for me so I'm still just learning how to do this stuff. I've found several ways to make it run on every sheet but I don't want it to do that. Basically, the workbook has a Billing sheet, individual month sheets (not used in this marco) and then individual client sheets. I want this to run on all my client sheets (currently 4 but will be growing). I appreciate any help. Here is the code I have:
Sub PetersBilling()
If ActiveSheet.Name = "Billing" Then
MsgBox ("Please choose another source sheet.")
Else
Dim rSourceName As String
Dim rSourceInvDate As String
Dim rSourcePayDate As String
Dim rSourceDecBill As String
Dim shCurrentPage As String
rSourceName = "='" & ActiveSheet.Name & "'!$C$5"
rSourceInvDate = "='" & ActiveSheet.Name & "'!$Q$5"
rSourcePayDate = "='" & ActiveSheet.Name & "'!$T$5"
rSourceDecBill = "='" & ActiveSheet.Name & "'!$P$21"
Sheets("Billing").Select
Range("B2").Select
Do Until Selection.Value = ""
Selection.Offset(1, 0).Select
Loop
Selection.Value = rSourceName
Selection.Offset(0, 1).Select
Selection.Value = rSourceInvDate
Selection.Offset(0, 1).Select
Selection.Value = rSourcePayDate
Selection.Offset(0, 1).Select
Selection.Value = rSourceDecBill
End If
End Sub
pmterp,
Welcome to the forum. In the future, please wrap your code in code tags. As to your request, you should be able to use the following code. Just change what's in BadSheets to be the names of sheets you don't want included in the macro.
Sub PetersBilling() Const BadSheets As String = "Billing,Jan,Feb,etc" Dim ws As Worksheet For Each ws In ActiveWorkbook.Sheets If InStr(1, BadSheets, ws.Name, vbTextCompare) = 0 Then Sheets("Billing").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).Resize(1, 4).Value = Array(ws.[C5].Value, ws.[Q5].Value, ws.[T5].Value, ws.[P21].Value) Next ws End Sub
Hope that helps,
~tigeravatar
Thank you so much. That does exactly what I want. I wish I understood how it works, but I'm content knowing it does.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks