How to combine two VBA macros

skv89

New Member
Joined
Jun 1, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
I'm a super noob at Excel VBA. I have a simple button macro and I have another macro with only two lines for copying cell values. I'm trying to combine the two macros but the two lines at the end for copying cell values don't work. Any help on how to get it to work is greatly appreciated!!

VBA Code:
Sub ButtonC_Click()

Dim MyCell As Range
Set MyCell = Sheets("Batch Input").Range("C32")

If Dir(ThisWorkbook.Path & "\" & MyCell.Value & ".xls") <> "" Then
    On Error Resume Next: Err.Clear: Dim wb As Workbook
    Set wb = Workbooks(MyCell.Value & ".xls"): wb.Activate
    If Err.Number > 0 Then Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & MyCell.Value & ".xls")
    If Not wb Is Nothing Then wb.Worksheets("Shear Wall Analysis").Activate Else MsgBox "File not found", vbInformation
Else
     FileCopy ThisWorkbook.Path & "\Wood Shear Wall Template.xls", ThisWorkbook.Path & "\" & MyCell.Value & ".xls"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & MyCell.Value & ".xls"
End If

Range("C67").Value = Range("C90").Value
Range("C68").Value = Range("C91").Value

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Welcome to the Board.

What is in C90 and C91? You could try writing it as

Range("C67")=Range("C90")
Range("C68")=Range("C91")
 
Upvote 0
Cross-posted at:
Please read Mr Excel's policy on Cross-Posting in rule 13: Message Board Rules
 
Upvote 0
Welcome to the Board.

What is in C90 and C91? You could try writing it as

Range("C67")=Range("C90")
Range("C68")=Range("C91")

The value means to copy value only and not the formula. C90 and C91 are concatenate formulas and C67 and C68 are external cell references. The copy works on its own but not when combined with the other macro.
 
Upvote 0
So the first macro works independently and does the second work independently?
 
Upvote 0
Suggestion then is to create a third subroutine and use the call command to see if that resolves it. If that doesn't work try adding in a time delay within the third subroutine (after the first call and before the second call) to see if that then works. Time events sometimes are needed and useful for so many different things.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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