Combine VBA Codes together

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi there,
I currently have VBA code under both Module and the Worksheet which I would like to combine under one macro to run together. Independently, they all work fine. Below are the codes and in the order I would like them to run. All information is located on Sheet81 but the macro will be run from Sheet13 (so it all needs to be under Module11). I tried fudging them together but I'm outside my depth. Your help would be appreciated! Thank you!

'First code to run, currently on Sheet81
Sub ssFav()
Dim response As String
response = InputBox("1/3 Enter notes to client regarding Input tax..")
Range("D53").Value = response


response = InputBox("2/3 Enter notes to client regarding Output tax..")
Range("D101").Value = response


response = InputBox("3/3 Enter notes to client regarding Overall Balance..")
Range("D106").Value = response
End Sub


' Second codes to run, currently on Sheet81
Sub tlc53()
Dim Cl As Range
For Each Cl In Sheet81.Range("I15:I49")
Cl.EntireRow.Hidden = IIf(Cl = 0, True, False)
Next Cl
End Sub


Sub tlc534()
Dim Cl As Range
For Each Cl In Sheet81.Range("I63:I97")
Cl.EntireRow.Hidden = IIf(Cl = 0, True, False)
Next Cl
End Sub

Last code to run, currently under Module11
Option Explicit
Sub PDFActiveSheetGSTREC()
'www.contextures.com
'for Excel 2010 and later
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
Dim blnWasSheetHidden As Boolean
On Error GoTo errHandler


Set wbA = ActiveWorkbook
Set wsA = Sheet80


'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & ""


strName = wsA.Range("A1").Value _
& " - " & wsA.Range("A2").Value _
& " " & Format(wsA.Range("A3"), "dd.mm.yy")


'create default name for savng file
strFile = strName & ".pdf"
strPathFile = strPath & strFile


'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strName & ".pdf", _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")


'export to PDF if a folder was selected
If myFile <> "False" Then
If wsA.Visible = xlSheetHidden Then
wsA.Visible = xlSheetVisible
blnWasSheetHidden = True
End If
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
If blnWasSheetHidden = True Then
wsA.Visible = xlSheetHidden
End If
'confirmation message with file info
MsgBox "PDF file has been created: " _
& vbCrLf _
& myFile
End If


exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If they are all running one after the other i'd just call them in a different sub

Code:
Sub runall()
[COLOR=#333333]ssFav
[/COLOR][COLOR=#333333]tlc53[/COLOR]
[COLOR=#333333]PDFActiveSheetGSTREC[/COLOR]
End sub
 
Upvote 0
Thanks. I've tried adding your code to sheet13 and also putting it under a new module but neither work.
Returns error, Sub or Function not defined.
 
Upvote 0
I see the issue now, apologies.

Code:
Sub runall()
With Sheet81
.ssFav
.tlc53
.[COLOR=#333333]tlc534
[/COLOR]End With
PDFActiveSheetGSTREC
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,755
Messages
6,180,766
Members
452,996
Latest member
nelsonsix66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top